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

<!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>

效果图:

 

转载于:https://www.cnblogs.com/huanghuali/p/7045667.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值