首页 > Web开发 > 详细

点击返回页面顶部-js

时间:2016-07-07 06:15:37      阅读:170      评论:0      收藏:0      [点我收藏+]
   <script>
        window.onload=function(){
            var oBtn = document.getElementById(‘btn‘);
            var turn =false ;
            var time = null ;
            window.onscroll=function(){

                if(turn){
                    clearInterval(time)
                }
                turn =true ;
            }
            oBtn.onclick=function () {

                time=  setInterval(function(){

//                    document.body.scrollTop谷歌浏览器支持 document.documentElement.scrollTopIE以及火狐支持
                    var scroll=document.documentElement.scrollTop||document.body.scrollTop ;
                    var spend =Math.floor( -scroll/20 ) ;
                    if(scroll==0){
                        clearInterval(time)
                    }

                    document.documentElement.scrollTop=document.body.scrollTop=scroll+spend;
                    turn =false;

                },30)

            }
        }
    </script>

 

点击返回页面顶部-js

原文:http://www.cnblogs.com/web-long/p/5648643.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!