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.