码迷,mamicode.com
首页 > Web开发 > 详细

js返回顶部动画效果

时间:2018-02-12 00:25:53      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:www   返回   body   ==   post   class   inter   interval   col   

// 返回顶部
    function goTop(){
        // 无动画效果
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;

        // 简单动画效果
        $("html,body").animate({scrollTop:0},500);

        // 由快到慢的效果
        scrollToptimer = setInterval(function () {
            console.log("定时循环回到顶部")
            var top = document.body.scrollTop || document.documentElement.scrollTop;
            var speed = top / 4;
            if (document.body.scrollTop!=0) {
                document.body.scrollTop -= speed;
            }else {
                document.documentElement.scrollTop -= speed;
            }
            if (top == 0) {
                clearInterval(scrollToptimer);
            }
        }, 30); 
    }

参考来自:http://www.cnblogs.com/li-you/p/7275239.html

js返回顶部动画效果

标签:www   返回   body   ==   post   class   inter   interval   col   

原文地址:https://www.cnblogs.com/xushengguan/p/8443486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!