The ScrollToOptions
dictionary of the CSSOM View spec contains properties specifying where an element should be scrolled to, and whether the scrolling should be smooth.
A ScrollToOptions
dictionary can be provided as a parameter for the following methods:
ScrollToOptions.top
ScrollToOptions.left
ScrollToOptions.behavior
ScrollOptions
dictionary, which is implemented by ScrollToOptions
.In our scrolltooptions example (see it live) we include a form that allows the user to enter three values — two numbers representing the left and top properties (i.e. the positions to scroll to along the X and Y axes), and a checkbox indicating whether they want smooth scrolling enabled or not.
When the form is submitted, an event handler is run that puts the entered values into a ScrollToOptions dictionary, and then invokes the Window.ScrollTo()
method, passing the dictionary as a parameter:
form.addEventListener('submit', (e) => { e.preventDefault(); scrollOptions = { left: leftInput.value, top: topInput.value, behavior: scrollInput.checked ? 'smooth' : 'auto' } window.scrollTo(scrollOptions); });
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View Module The definition of 'ScrollToOptions' in that specification. | Working Draft |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 45 | No | Yes | No | 32 | No |
behavior |
45 | No | Yes | No | 32 | No |
left |
45 | No | Yes | No | 32 | No |
top |
45 | No | Yes | No | 32 | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 45 | 45 | No | Yes | 32 | No | Yes |
behavior |
45 | 45 | No | Yes | 32 | No | Yes |
left |
45 | 45 | No | Yes | 32 | No | Yes |
top |
45 | 45 | No | Yes | 32 | No | Yes |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ScrollToOptions