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

滑到离顶部一定距离显示,返回顶部和底部2

时间:2017-06-18 23:36:58      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:ima   效果   ready   display   blog   分享   read   end   pad   

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
    * {
        margin: 0;
        padding: 0;
    }
    #icon_top_end{ display: none;}
    
    #back-top {
        position: fixed;
        bottom: 20px;
        right: 2%;
        z-index: 100;
       
    }
    
    #back-end {
        position: fixed;
        bottom: 40px;
        right: 2%;
        z-index: 100;
    }
    </style>
</head>

<body>
    <!-- 侧边栏 按钮-->
    <div style="width: 200px; height: 500px; background-color: #ccc; margin: 0 auto;"></div>
    <div style="width: 200px; height: 500px; background-color: #ccc; margin: 0 auto;"></div>
    <div style="width: 200px; height: 500px; background-color: #ccc; margin: 0 auto;"></div>
    <div style="width: 200px; height: 500px; background-color: #edfefe; margin: 0 auto;"></div>
    <div id="icon_top_end">
    <div id="back-top">
        <button class="styled-button">TOP</button>
    </div>
    <div id="back-end">
        <button class="styled-button">Bottom</button>
    </div>
    </div>
    <!--底部 内容-->
    <div id="footer"></div>
    <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
                /**
                 * 回到顶部
                 */
                $(window).scroll(function() {
                        if ($(this).scrollTop() > 100) {
                            $(#icon_top_end).show(slow);
                        } else {
                            $(#icon_top_end).hide(slow);
                        }
                    });
                    $(#back-top).click(function() {
                        $(html,body).stop();
                        $(html,body).animate({
                            scrollTop: 0px
                        }, 1000);
                    });

                    /**`1
                     * 回到底部
                     */
                    $(#back-end).click(function() {
                        $(html,body).stop();
                        $(html,body).animate({
                            scrollTop: $(#footer).offset().top
                        }, 1000);
                    });
                });
    </script>
</body>

</html>

效果图:

技术分享

 

滑到离顶部一定距离显示,返回顶部和底部2

标签:ima   效果   ready   display   blog   分享   read   end   pad   

原文地址:http://www.cnblogs.com/huanghuali/p/7045667.html

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