[英]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.