• 回到顶部bug


    参考自一博客(https://www.cnblogs.com/abao0/p/6642288.html)内有慕课网教程(后发现有bug, 弃置不用了)

    以下有问题, 当滚动条处于顶部时, 刷新页面, 回到顶部icon依然会出现.

    //Page loading trigger
    window.onload = function () {
        var oscrollBtn = document.getElementById('scrollBtn');
        var timer = null;
        var isTop = true;
        //Gets the height of the visible window
        var clientHeight = document.documentElement.clientHeight;//Triggered when the scroll bar rolls
        window.onscroll = function () {
            var osTop = document.documentElement.scrollTop || document.body.scrollTop;
            if (osTop >= clientHeight) {
                oscrollBtn.style.display = 'block';
            } else {
                oscrollBtn.style.display = 'none';
            }
            if (!isTop) {
                clearInterval(timer);
            }
            isTop = false;
        }
        oscrollBtn.onclick = function () {
            //Set timer
            timer = setInterval(function () {
                //Gets the height of the scroll bar
                var osTop = document.documentElement.scrollTop || document.body.scrollTop;
                //The scroll bar slows down
                var ispeed = Math.ceil(osTop / 6);
                document.documentElement.scrollTop = document.body.scrollTop = osTop - ispeed;
                isTop = true;
                if (osTop == 0) {
                    clearInterval(timer);
                }
            }, 30);
    
        }
    }
  • 相关阅读:
    centos pptp客户端 连接服务端
    工控上常见的通讯接口与协议
    winform无边框窗体拖动
    Winform实现窗体渐变色
    Win10系统安装
    WIN 10 系统能正常使用WLAN,无法连接以太网
    C#DataGridView分页显示数据
    遍历枚举的值
    C#dataGridView添加自增列
    Winform实现打印功能
  • 原文地址:https://www.cnblogs.com/yadongliang/p/9313583.html
Copyright © 2020-2023  润新知