Reputation: 29159
I have this scrollable list
<ol>
<li>...</li>
...
</ol>
Now, I can scroll programatically using
document.querySelector('ol').scrollTo(100);
But this doesn't work in Safari. Although this seems to be trivial, I cannot find the alternative (without using jQuery)
How to make the list scrollable in Safari?
Upvotes: 4
Views: 17692
Reputation: 956
scrollTo
is a property of window
object. And you are trying to apply it on an element
.
Use
element.scrollTop
Code Snippet
document.querySelector('ol').scrollTop = 100;
It will do the trick!
For more information on scrollTo
& scrollTop
, refer Mozilla/Window/scrollTo & Mozilla/Element/scrollTop respectively.
NOTE
document.querySelector(selectors)
returns the first element within thedocument
. If yourdocument
contains multiple<ol>
elements, it will always return the first element.To select specific element, you can assign an
ID
& refer the element bydocument.querySelector('#ID')
.
Hope it helps!
Upvotes: 3
Reputation: 72
I believe this will help you: Scroll to position WITHIN a div (not window) using pure JS
There is alternative way to get what you wished.
Upvotes: 0