There is a function that requires determining whether the button to return to the top is displayed.
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"; }But I found that document.body.scrollTop has always been 0.
I found that it was a DTD problem after searching the information.
The page specifies DTD, that is, when DOCTYPE is specified, document.documentElement is used.
The page does not have DTD, that is, when DOCTYPE is not specified, document.body is used.
This is true for both IE and Firefox.
And my page has <!DOCTYPE html> added, so it is as follows.
/*Judge whether the button is displayed on the top.*/ window.onscroll=function(){ var sTop = document.documentElement.scrollTop; if(sTop>100){ document.getElementById("sm_top").style.display="block"; }else{ document.getElementById("sm_top").style.display="none"; } }The above is the solution to the Document.body.scrollTop value is always zero that the editor introduced to you. I hope it will be helpful to everyone!