html部分:
<body style="height:2000px">
<div id="div1">
返回顶部
</div>
</body>
css部分:
#div1{ position:fixed; _position:absolute; right:0; bottom:0; 200px; height:200px; background:#f00; display:none; }
js部分:
window.onscroll=function(){ if(-[1,]){ var y=window.pageYOffset; }else{ var y=document.documentElement.scrollTop; } var div1=document.getElementById("div1"); if(y>=150){ div1.style.display="block"; }else{ div1.style.display="none"; } div1.onclick=function(){ window.scrollTo(0,0); } }