zoukankan      html  css  js  c++  java
  • scroll滚动到一定距离触发事件/返回顶部animate

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style type="text/css">
        	*{margin: 0; padding: 0;}
        	.box{  960px; height: 1800px; background: #F29292; margin: 0 auto; }
        	.gotop{  60px; height: 60px; background: red; position: fixed; left: 50%; bottom: 50px; margin-left: 480px; display: none; }
        </style>
        <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
        $(function() {
            //scroll 事件适用于所有可滚动的元素和 window 对象(浏览器窗口)。
            $(window).scroll(function() {
                    var scroHei = $(window).scrollTop();//滚动的高度
                    if (scroHei > 400) {
                        $('.J_goTop').fadeIn();
                    } else {
                        $('.J_goTop').fadeOut();
                    }
                })
                /*点击返回顶部*/
            $('.J_goTop').click(function() {
                $('body,html').animate({
                    scrollTop: 0
                }, 600);
            })
        })
        </script>
    </head>
    
    <body>
    <div class="box"></div>
    <div class="gotop J_goTop">返回顶部</div>
    </body>
    
    </html>
    

      如图:

  • 相关阅读:
    爬虫框架scrapy(1)持久化存储的多种方式及多页爬取数据
    爬虫之selenium
    redis相关
    爬虫之数据解析
    爬虫之requests模块2
    爬虫之requests模块
    HTTP和HTTPS协议
    Pymongo使用
    MongoDB
    python网络编程之黏包问题
  • 原文地址:https://www.cnblogs.com/huanghuali/p/6667631.html
Copyright © 2011-2022 走看看