jquery返回顶部特效

浏览:353 发布日期:2017/03/03 分类:技术分享
<style>
    p#back-to-top{position:fixed; bottom:100px;right:10px; display: none; }
    p#back-to-top a{ text-align:center;  text-decoration:none;  color:#d1d1d1;  display:block;  width:30px;
        /*使用CSS3中的transition属性给跳转链接中的文字添加渐变效果*/
        transition:color 1s; -moz-transition:color 1s;
        -webkit-transition:color 1s;
        -o-transition:color 1s;}
    p#back-to-top a span{
        background:url(images/ico.jpg) no-repeat; display:block;height:30px;  width:30px;margin-bottom:5px;
        /*使用CSS3中的transition属性给<span>标签背景颜色添加渐变效果*/
        transition:background 1s;  -moz-transition:background 1s;-webkit-transition:background 1s;-o-transition:background 1s;}
</style>

<div style="width: 100%; height: 3000px;"></div>
<p id="back-to-top"><a href="#top"><span></span>返回顶部</a></p>

<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script>
    $(function(){
        $(window).scroll(function(){
            if($(window).scrollTop()>=100){
                $("#back-to-top").fadeIn(1500); //缓慢的将段落淡入
            }
            else{
                $("#back-to-top").fadeOut(1500); //缓慢的将段落淡出
            }
        })
        $("#back-to-top").click(function(){
           $('body.html').animate({scrollTop},1000);
           return false;
       })
    })
</script>
最佳答案
评论() 相关
后面还有条评论,点击查看>>