码迷,mamicode.com
首页 > 其他好文 > 详细

返回顶部

时间:2016-12-20 23:25:31      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:div   position   显示   round   point   pre   等于   ima   不显示   

1、HTML结构

<div class="return_top"></div>

2、css样式

.return_top{ 
    width: 50px; 
    height: 50px; 
    background: url(../images/lanren.gif) no-repeat center #FF8D16; 
    position:fixed; 
    right: 30px; 
    bottom: 30px; 
    display: none; 
    cursor: pointer; 
    z-index: 99;
}

3、js效果

<script>
     $(function(){
        $(window).scroll(function(){
            var topDistance=$(window).scrollTop();    //获取鼠标在本窗口现有状态下移动的高度
            if(topDistance>100){    //如果移动高度大于100px,顶部图标单单显示出,如果移动高度小于等于100,顶部图标不显示
                $(‘.return_top‘).fadeIn(800);
            }else{
                $(‘.return_top‘).fadeOut(800);
            }
        });
        $(‘.return_top‘).on(‘click‘,function(){
            $(‘html,body‘).animate({scrollTop:0},800); //必须用$(‘html,body‘)选择,不然没效果
        })
    });
</script>

 

返回顶部

标签:div   position   显示   round   point   pre   等于   ima   不显示   

原文地址:http://www.cnblogs.com/wuxibolgs329/p/6204617.html

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