


Solution to the problem that document.body.scrollTop value is always 0. Common standard problems_javascript skills
When making pages, you may use fixed-position layers. Read document.body.scrollTop to set the position of the layer, like this:
window.onscroll = function (){
var oFix = document .getElementById("divfix");
oFix.style.top = document.body.scrollTop "px";
}
But why did it not achieve the expected effect, output document.body.scrollTop Looking at the value, it is always 0. It turns out to be a DTD problem. If the page starts directly with , there will be no problem. But to comply with web standards, DTD is of course indispensable. When you have a DTD just use document.documentElement.scrollTop instead of document.body.scrollTop.
window.onscroll = function (){
var oFix = document.getElementById("divfix");
oFix.style.top = document.documentElement.scrollTop "px";
}
Editor's Note:
When the page has a DTD (or DOCTYPE is specified), use document.documentElement.
When the page does not have a DTD (or DOCTYPE is not specified), use document.body.
This is true in both IE and Firefox.
For compatibility, you can use the following code: var scrollTop = window.pageYOffset
|| document.documentElement.scrollTop
|| document.body.scrollTop
|| 0;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



As the importance of PHP in Web development continues to increase, PHP function library design has become one of the key issues in development. A good function library can not only improve development efficiency, but also ensure code quality and maintainability. Therefore, designing function libraries needs to follow some basic principles and standards. 1. A function library with good reusability should be reusable and can be used in different projects. Therefore, functions should be abstract and general and cannot be tied to a specific project or scenario. 2. Ease of use The function library should be easy to use and pass parameters

PHP functions can be classified according to various criteria: purpose (string processing, array processing, etc.), scope (built-in functions, user-defined functions) and return value (with or without return value). Practical case: The explode() function can split a string into an array with a specified delimiter.

How to judge the criteria for sticky positioning? Revealing the key elements of sticky positioning Introduction: Sticky positioning, as a market positioning strategy, plays a vital role in corporate brand promotion and market competition. However, how to judge the criteria for sticky positioning is a headache. This article will reveal the key elements of sticky positioning and help companies better judge the criteria for sticky positioning. 1. Understand the significance of sticky positioning Sticky positioning means that an enterprise generates strong identification and loyalty among consumers through its unique brand characteristics and core competitive advantages, thus forming a

The standard of sticky positioning refers to the ability of a company or brand to occupy a fixed position in consumers' minds for a long time in market competition and to stably maintain market share and brand loyalty. Sticky positioning is an important concept in marketing. It emphasizes that in a fiercely competitive market environment, companies need to establish their own unique positioning and establish close relationships with consumers to maintain competitive advantages. The core requirements of sticky positioning include the following aspects: Uniqueness: The positioning of a company or brand in the market must be unique and different from competitors.

Recently, there has been increasing discussion about generative artificial intelligence tools, especially after the release of several large-scale language models and image generators such as DALL-E or Midjourney. These inventions have once again put general artificial intelligence (GPAI) under the spotlight and once again raised hypothetical questions such as whether GPAI should be regulated. Before one explores the possibilities further, first understand the concept of GPAI, what it means, when was it introduced, etc. What is general artificial intelligence? Two years ago, in April 2021, the European Commission launched general artificial intelligence. The original AI bill proposal exempted creators of general artificial intelligence from complying with a number of legal instruments and other liability standards. reason

In web development, PHP is a widely used programming language. Its standard tags are special tag symbols in PHP code that are used to identify the beginning and end of PHP code. It is very important to have an in-depth understanding of PHP's standard tags because they directly affect the parsing and execution process of PHP code. This article will delve into PHP's standard tags and provide specific code examples to help readers better understand and use PHP programming. 1. PHP standard tags In PHP, the most commonly used standard tags are "

Title: Does the Go language meet the standards of upper-level languages? In recent years, Go language, as an emerging programming language, has received widespread attention and application. As a statically typed, compiled language, the Go language has unique advantages in concurrent programming, memory management, and code readability. However, in the eyes of some programmers, it does not fully meet the standards that upper-level languages should have. This article will discuss whether the Go language meets the standards of the upper-level language from several aspects, and discuss it with specific code examples. 1. Code simplicity. Upper-level languages are usually

Sticky positioning is a common web layout technique that provides a better user experience by keeping elements in a fixed position as they are scrolled. This article will analyze the standards, elements, and requirements for sticky positioning, and provide specific code examples. 1. Standard compatibility of sticky positioning: Sticky positioning should work normally on mainstream browsers, such as Chrome, Firefox, Safari, etc. Scroll effect: Elements should transition smoothly when scrolling to avoid flickering or jittering. Responsive design: Sticky positioning should adapt to different devices and screen sizes to ensure
