Page scroll, Back to top button Show / Hide

To get the scroll bar ordinate position of the current page:

document.documentElement.sctrollTop;

Instead of:

document.body.scrollTop;

documentElement corresponds html tags, the tag body corresponds to the body

In w3c standard, document.body.scrollTop constant at 0, instead of the need document.documentElement.scrollTop

window.scroll = function(){

if(document.documentElement.scrollTop+document.body.scrollTop >50){

  document.getElementById('#test').style.display ="block";

}else{

  document.getElementById("#test").style.display = "none";

}

}

Guess you like

Origin www.cnblogs.com/sjzgk/p/11403936.html