有人可以帮助我处理网站上的活动吗?问题是,每次触发滚动事件时它们都会重复出现。导航菜单位于标题下方,但在滚动时粘在顶部,但我希望当我们一直向上滚动时它回到标题下方。我不知道我做错了什么。这是我的代码:
var navigation = document.querySelector("nav");
var borderBottom = navigation.getAttribute("border-bottom");
var currentDistance = (document.documentElement.scrollHeight);
addEventListener ("scroll", function() {
if (currentDistance > "90px") {
navigation.style.position = "fixed";
navigation.style.top = "0";
navigation.style.borderBottom = "3px solid rgb(157,0,53)";
}
else removeEventListener ("scroll", function() {
navigation.style.position = "fixed";
navigation.style.top = "0";
navigation.style.borderBottom = "3px solid rgb(157,0,53)";
}
);
});
Run Code Online (Sandbox Code Playgroud)
此外,当页面加载并触发滚动事件时,一个 div 飞入,这就是我想要的。但我的问题是,每次触发滚动事件时,盒子都会不断飞入,而不是事件停止,即不断重新发生。这是我使用的代码:
var flyInDiv = document.getElementById("flyInDiv");
addEventListener ("scroll", function() {
var programMenu = document.createElement("DIV");
programMenu.className = "programMenu";
programMenu.appendChild(flyInDiv);
document.body.appendChild(programMenu);
programMenu.style.position = "fixed";
});
Run Code Online (Sandbox Code Playgroud)
我网站的 URL 是 …