[英]How to smooth scroll to div on scroll using vanilla JS?
我正在寻找一种在滚动时滚动到 div 的方法 - 仅在登陆 Id 上不寻找所有部分的整页滚动。
我的代码段中的 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.