【发布时间】:2021-06-12 20:44:48
【问题描述】:
我的网站上只有两个脚本,一个它们可以工作,它们不能一起工作......我在这里错过了什么?
第一个脚本:
window.onscroll = function() {myFunction()};
var navigation = document.getElementById("navigation");
var sticky = navigation.offsetTop;
function myFunction() {
if (window.pageYOffset > sticky) {
navigation.classList.add("sticky");
} else {
navigation.classList.remove("sticky");
}
}
第二个脚本:
mybutton = document.getElementById("tothetop");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 98 || document.documentElement.scrollTop > 98) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
我不明白他们为什么不一起工作。
【问题讨论】:
-
两个函数不能一起工作是什么意思?是您的第一个函数没有调用该函数还是两者都不起作用。
标签: javascript css scrolltop