日期:2014-05-16 浏览次数:20401 次
// JavaScript Document 回到顶部
function goTopEx(){
var obj=document.getElementById("goTopBtn");
function getScrollTop(){
var xtop;
xtop = document.documentElement.scrollTop || document.body.scrollTop;
return xtop;
}
function setScrollTop(value){
if (document.body)
{
document.documentElement.scrollTop=value;
}
else
{
document.documentElement.body=value;
}
}
window.onscroll=function(){getScrollTop()>0?obj.style.display="block":obj.style.display="none";}
obj.onclick=function(){
var gotop;
gotop=window.setInterval(scrollMove,10);
function scrollMove(){
setScrollTop(getScrollTop()/3);
if(getScrollTop()<1)
{
window.clearInterval(gotop);
}
}
alert(gotop);
}
}
<DIV style="DISPLAY: none" id=goTopBtn><IMG border=0 src="{res file=images/toTop.png}"></DIV>
<SCRIPT type=text/javascript>goTopEx();</SCRIPT>
obj.onclick=function(){
var gotop;
gotop=window.setInterval(function(){
setScrollTop(getScrollTop()/3);
if(getScrollTop()<1)
{
window.clearInterval(gotop);
}
},10);
alert(gotop);
}