JS代码:
<script type="text/javascript">
//实现回到页面顶部
function goTopEx(){
var obj=document.getElementById("goTopBtn");
function getScrollTop(){
//谷歌浏览器
return document.body.scrollTop;
//IE浏览器
//return document.documentElement.scrollTop;
}
function setScrollTop(value){
//谷歌浏览器
document.body.scrollTop=value;
//IE浏览器
//document.documentElement.scrollTop=value;
}
window.οnscrοll=function(){getScrollTop()>100?obj.style.display="":obj.style.display="none";}
obj.οnclick=function(){
var goTop=setInterval(scrollMove,10);
function scrollMove(){
setScrollTop(getScrollTop()/1.1);
if(getScrollTop()<1)clearInterval(goTop);
}
}
}
</script>
CSS代码:
<style type="text/css">
#goTopBtn {
position: fixed; text-align: center; line-height: 30px; width: 30px; bottom: 150px; height: 33px; font-size: 12px; cursor: pointer; right: 100px; _position: absolute; _right: auto
}
</style>
HTML代码:
<DIV style="display: none" id=goTopBtn><IMG border=0 src="image/top1.gif"></DIV>
<script type=text/javascript>goTopEx();</script>