zoukankan      html  css  js  c++  java
  • dom 回到顶部(兼容IE FF Chrome)

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style>
     #wrap{
         height:2000px;
         background:pink;
         position:relative;
         }
     #ontop{
         position:absolute;
         bottom:0px;
         right:0px;
         background:red;
         color:#FFF;
         font-weight:bold;
         height:100px;
         100px;
         line-height:100px;
         text-align:center;
         cursor:pointer;
         }     
    </style>
    <script type="text/javascript">
    window.onload = function ()
    {
        var otop = document.getElementById('ontop');
        var timer = null;
        
        otop.onclick = function ()
        {
            timer = setInterval(function()
            {
                document.body.scrollTop -= 50;
                document.documentElement.scrollTop -= 50;
                if(document.body.scrollTop == 0 && document.documentElement.scrollTop == 0 )
                {
                    clearInterval(timer);
                }
                
            },20)
            
            
            
            
        };
    };
    </script>
    </head>
    
    <body>
    <div id="wrap">
        <span id="ontop">回到顶部</span>
    </div>
    </body>
    </html>
  • 相关阅读:
    ASIX配置vlan tag能被wireshark获取
    翻译-cmake教程
    Manjaro打造开发环境
    Frida入门
    安卓应用启动底层执行逻辑
    集合框架
    oracle清除日志内存
    flutter widgets目录
    给设备添加udid
    5.class
  • 原文地址:https://www.cnblogs.com/mayufo/p/4208100.html
Copyright © 2011-2022 走看看