javascript - 在每个滚动条上移动元素
问题描述
我正在尝试根据车轮增量值将“主”标记名向上或向下移动 100 个视口高度,以使窗口内的部分发生变化。还有一种在指定时停止或开始执行代码的方法,但我无法弄清楚该函数应该是什么才能正确执行它。
window.addEventListener("wheel", event => {
const delta = Math.sign(event.deltaY);
//console.info(delta);
if (delta > 0) {
nextSection();
} else if (delta < 0) {
previousSection();
}
let main = document.querySelector("main");
var mainTop = main.style.top
function nextSection() {
console.log("next-section");
let sections = document.querySelectorAll("section");
let mainTop = "0";
function countP() {
mainTop += 100;
main.style.top = mainTop;
}
}
function previousSection() {
console.log("previous-section");
}
});
html,
body {
margin: 0;
padding: 0;
overflow: hidden;
user-select: none;
}
main {
position: absolute;
top: 0;
right: 0;
left: 0;
}
main>section {
position: absolute;
right: 0;
left: 0;
width: 100vw;
height: 100vh;
}
#first-section {
top: 0;
background-color: black;
}
#myVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
#services {
top: 100vh;
background-color: transparent;
}
#about-us {
top: 200vh;
background-color: yellow;
}
#ecommerce {
top: 300vh;
background-color: darkcyan;
}
#testimonials {
top: 400vh;
background-color: deeppink;
}
#footer {
position: absolute;
top: 33vh;
right: 0;
left: 0;
width: 100%;
height: 67vh;
background-color: black;
z-index: -1;
}
<!DOCTYPE html>
<html lang="english">
<head>
<title></title>
</head>
<body>
<main>
<section id="first-section"></section>
<section id="services"></section>
<section id="about-us"></section>
<section id="ecommerce"></section>
<section id="testimonials"></section>
</main>
<footer id="footer"></footer>
</body>
</html>
解决方案
推荐阅读
- maven - Import Spring Boot (or other open source framework) related/dependent jar files to Local Artifactory repo
- c++ - 从 csv 文件中获取不同类型的数据并将其放入 C++ 中的 typedef 结构中
- python - 由于缩进,一段聊天机器人代码没有执行?
- delphi - Different behavior on explicit cast from double to currency on different Delphi installations
- python - 使用熊猫替换正则表达式重新格式化字符串内的日期
- jquery - 在前端执行 PUT 和 DELETE
- c++ - Code::Blocks 说在 linux 上找不到 icon.res
- excel - 如何使用 VBA 中的矩阵和循环查找并绘制具有相同内部单元格颜色的表的所有等值?
- javascript - JavaScript Split on Any Number of a Character
- java - My application getting crashes even though there is no error while building the app