المعرفة:: JavaScript
الحالة::مؤرشفة
المراجع:: The Complete JavaScript Course 2022 From Zero to Expert, Build Responsive Real-World Websites with HTML and CSS Study Notes
- Using
window.scrollTo
we can scroll to a particular set of coordinates in the document.
- Usually the two coordinates are left and top.
window.scrollTo
also accepts an options object with top, left, and behavior key-values.
behavior
is set to auto
by default, but it can be set to smooth
.
- Alternatively, a modern way of doing the same is to use
scrollIntoView
on any element with behavior
set to smooth
.
Example