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

返回头部和底部,初始隐藏!

时间:2016-11-30 13:43:20      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:top   回到顶部   class   script   java   html   var   返回   rip   

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script type="text/javascript" src="js/jquery-1.8.3.js" ></script>
        <style>
            .gotop{
                width:50px;
                height:50px;
                background: darkred;
                color: #fff;
                font-size: 16px;
                position: fixed;
                right:20px;
                bottom: 200px;
                cursor: pointer;
                display: none;
            }
            .gobottom{
                width:50px;
                height:50px;
                background: darkred;
                color: #fff;
                font-size: 16px;
                position: fixed;
                right:20px;
                bottom: 140px;
                cursor: pointer;
                display: none;
            }
        </style>
    </head>
    <body>
        <div style="height:2000px;width:800px;margin:0 auto;background: green;">
            
            
        </div>
        <div class="gotop">
            回到顶部
        </div>
        <div class="gobottom">
            回到底部
        </div>
        
    </body>
    <script>
       function gotop(){
             $(window).scroll(function(){
                 var s=$(window).scrollTop();
                 s>150 ? $(".gobottom,.gotop").css("display","block") : $(".gobottom,.gotop").css("display","none");
             });
             $(".gotop").live("click",function(){
                 $("html,body").animate({scrollTop:0})
             })
             var h=$("html").height();
             $(".gobottom").live("click",function(){
                 $("html,body").animate({scrollTop:h})
             })
       }
       gotop();
    </script>
</html>

返回头部和底部,初始隐藏!

标签:top   回到顶部   class   script   java   html   var   返回   rip   

原文地址:http://www.cnblogs.com/lym520/p/6117068.html

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