首页 > Web开发 > 详细

JS 回到顶端 back to top

时间:2017-10-02 11:14:26      阅读:321      评论:0      收藏:0      [点我收藏+]
CSS:
.backtoTop2{
    height: 40px;
    width: 50px;
    position: fixed;     
    padding-top: 8px;
    right: 100px;
    z-index: 9999;
    background: red;
    cursor: pointer;
    text-align: center;
}

JS:
$(document).ready(function(){
    $(window).scroll( function() {                    // change scroll event
        var height = $(window).height(),          //get window height
              top = $(document).scrollTop();       //get scroll top
        if(top > height ){                                    //more than height to show
            $("#backToTop2").fadeIn(300).css({
                top: height-80
            });
        }
        if(top < height ){                                   //less than height to disappear
            $("#backToTop2").fadeOut(200);
        }
    });
    /*back to top click*/
    $(‘#backToTop2‘).click(function(){
        $(‘html, body‘).animate({                     // Animation effects --> move
            scrollTop: 0
        }, 500);
    });
});
  
HTML:
<divid="backToTop2"class="backtoTop2"></div>

  

JS 回到顶端 back to top

原文:http://www.cnblogs.com/zwcai/p/7619816.html

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