这个在ie、ff都没效果,不兼容。就gg是ok的。大家都是这样的吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
window.onload=function(){
var oBack=document.getElementById('back');
var off=true;
var timer=null;
window.onscroll=function(){
if(!off){
clearInterval(timer)}
console.log(!off)
off=false;
}
oBack.onclick=function(){
timer=setInterval(fn1,30)
function fn1(){
var num=document.documentElement.scrollTop||document.body.scrollTop;
off=true;
var speed=Math.floor(-num/6)
document.documentElement.scrollTop=document.body.scrollTop +=speed;
if(num<=0){clearInterval(timer)}
}
}
}
</script>
</head>
<body>
<div style="width:1000px;margin:0 auto;background:linear-gradient(to bottom,#000,#fff);height:2000px;"></div>
<div id="back" style="position:fixed;right:10px;bottom:10px;"><img src="images/top.png"/></div>
</body>
</html>