📅  最后修改于: 2023-12-03 15:05:56.891000             🧑  作者: Mango
When developing web applications, it is often necessary to scroll the page to a certain position. This is where the window.scroll
method in Javascript comes in handy.
window.scroll(x-coord, y-coord)
x-coord
: Required. The horizontal pixel value of where to scroll to.y-coord
: Required. The vertical pixel value of where to scroll to.window.scroll(0, 500);
This will scroll the page to a position where the y
coordinate is 500
.
window.scroll
method is equivalent to window.scrollTo
.x
and y
properties, like so:window.scroll({ top: 500, left: 0, behavior: 'smooth' });
behavior
property can be set to 'auto'
or 'smooth'
to specify the scrolling behavior. 'smooth'
will create a smooth scrolling animation, whereas 'auto'
will not. The default value is 'auto'
.