【发布时间】:2021-12-18 19:46:27
【问题描述】:
您好,希望您今天过得愉快,
今天我决定在空闲时间尝试从 jquery 转换为 vanilla javascript,但我已经处理了几个小时的代码,我真的很难将这段代码从 Jquery 转换为 vanilla javascript。
我想更改的代码
$("h1").text(Math.round(progress) + "%").css({ color: textColor });
$(".fill").height(progress + "%").css({ backgroundColor: bgColor });
完整代码:
function progress() {
var windowScrollTop = $(window).scrollTop();
var docHeight = $(document).height();
var windowHeight = $(window).height();
var progress = (windowScrollTop / (docHeight - windowHeight)) * 100;
var bgColor = progress > 99 ? "#fff" : "#fff";
var textColor = progress > 99 ? "#fff" : "#333";
$("h1").text(Math.round(progress) + "%").css({ color: textColor });
$(".fill").height(progress + "%").css({ backgroundColor: bgColor });
}
progress();
对于所有的麻烦,我真的很抱歉,我希望你能帮助我解决我的问题。谢谢。
【问题讨论】:
标签: javascript jquery function ecmascript-6 jquery-selectors