【发布时间】:2020-11-05 13:14:54
【问题描述】:
我正在寻找一种在滚动时滚动到 div 的方法 - 仅在着陆 ID 上而不是在所有部分中寻找整页滚动。
我的 sn-p 中的 JS 已经在点击事件上工作,但不能让它在滚动上工作
document.getElementById('landing').addEventListener("scroll", function(event) {
event.preventDefault();
document.getElementById("main").scrollIntoView({ behavior: "smooth" });
});
#landing, #main {
height:100vh;
}
#main {
background: #EAEAEA;
}
<section id="landing"></section>
<section id="main"></section>
【问题讨论】:
-
你看过下面关于香草平滑实现的文章吗:webdesign.tutsplus.com/tutorials/…
-
我的问题是滚动事件侦听器不点击 - 这是一个很好的参考
标签: javascript