I've set the scroll functionality to smooth using CSS
scroll-behavior: smooth
I've been told it can be done using scrollIntoView or scrollTo, but I am a bit beginner to this. How do I turn that to pure JS?
scroll-behavior CSS property make the contents within an element scroll smoothly. While Element.scrollIntoView is used to programmatically scroll to an element.
If you want for example scroll to the header of the page with scroll-behavior: smooth
you can opt-in the behavior
option and set it to smooth
.
var header = document.getElementById("header")
header.scrollIntoView({ behavior: "smooth" })
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.