gpt4 book ai didi

javascript - 当我向下滚动我的网站页面时,如何让进度条更新?

转载 作者:行者123 更新时间:2023-11-28 14:10:15 24 4
gpt4 key购买 nike

我正在学习本教程:https://www.w3schools.com/howto/howto_js_scroll_indicator.asp ,但是当我向下滚动我的页面时,我无法让 javascript 工作。当我上下移动页面时,没有显示进度。我显示了灰色进度容器,但无法加载绿色部分。

我想知道它是否必须在我现有的代码中做一些可能会搞砸的事情?任何建议将不胜感激。

最佳答案

您最好使用 document.body 而不是 document.documentElement

// 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.body.scrollHeight - document.body.clientHeight;
var scrolled = (winScroll / height) * 100;

document.getElementById("myBar").style.width = scrolled + "%";
}

查看现场直播 - https://jsitor.com/pPcHN0v8a

关于javascript - 当我向下滚动我的网站页面时,如何让进度条更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56616600/

24 4 0
文章推荐: javascript - 如何根据表中的用户链接点击生成新的 HTML 页面?
文章推荐: css - 带有嵌套 div 的整个可点击
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com