Solution: document. body. scroll

Source: Internet
Author: User

Solution: document. body. scroll

There is a function that needs to determine whether the return button is displayed on the top.

The JS Code is as follows:

  var sTop = document.body.scrollTop;    if(sTop>100){        document.getElementById("sm_top").style.display="block";    }else{        document.getElementById("sm_top").style.display="none";    }

However, it is found that document. body. scrollTop is always 0.

Data Query is a DTD problem.

The page specifies DTD, that is, when doctypeis specified, use document.doc umentElement.

Document. body is used when no DTD is specified for the page, that is, DOCTYPE is not specified.

This is true for both IE and Firefox.

My page is added with <! DOCTYPE html>.

/* Determine whether to display the button back to the top */window. onscroll = function () {var sTop = document.doc umentElement. scrollTop; if (sTop> 100) {document. getElementById ("sm_top "). style. display = "block";} else {document. getElementById ("sm_top "). style. display = "none ";}}

 

 

Starof, the author of this article, is constantly learning and growing because of the changing knowledge. The content of this article is also updated from time to time. To avoid misleading readers and facilitate tracing, Please repost the Source: Ghost.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.