我正在添加页面滚动加载程序,比如水平线和顶部滚动按钮,在javascript的帮助下进入网站顶部

我正在添加页面滚动加载程序,比如水平线和顶部滚动按钮,在javascript的帮助下进入网站顶部,javascript,html,css,Javascript,Html,Css,当页面滚动加载程序工作时,顶部滚动按钮停止工作,当顶部滚动按钮工作时,页面滚动加载程序不工作 下面是javascript代码: // When the user scrolls the page, execute myFunction window.onscroll = function () { myFunction() }; function myFunction() { var winScroll = document.body.scrollTo

当页面滚动加载程序工作时,顶部滚动按钮停止工作,当顶部滚动按钮工作时,页面滚动加载程序不工作

下面是javascript代码:

// When the user scrolls the page, execute myFunction 
    window.onscroll = function () { myFunction() };
    
    function myFunction() {
        var winScroll = document.body.scrollTop || document.documentElement.scrollTop;
        var height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
        var scrolled = (winScroll / height) * 100;
        document.getElementById("myBar").style.width = scrolled + "%";
    }
    
    
    // =================Top button========
    
    
    //Get the button
    var mybutton = document.getElementById("myBtn");
    
    // When the user scrolls down 20px from the top of the document, show the button
    window.onscroll = function () { scrollFunction() };
    
    function scrollFunction() {
        if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
            mybutton.style.display = "block";
        } else {
            mybutton.style.display = "none";
        }
    }
    
    // When the user clicks on the button, scroll to the top of the document
    function topFunction() {
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;
    }
        // ==================================Top Button End=====================


检查此项:。这对你有帮助吗?我已经检查过了,但不起作用。