Mobile Safari: Why Is Window.Scrollto(0, 0) Not Scrolling to (0, 0)

window.scrollTo is not working in mobile phones

I got it finally working.

i had to use additionally the setTimeout function

setTimeout(window.scrollTo(x,y),100);

scrollTo not working in Safari

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
the document. If your document contains multiple <ol> elements,
it will always return the first element.

To select specific element, you can assign an ID & refer the element
by document.querySelector('#ID').

Hope it helps!

windows.scroll working in chrome but not in safari

You could try scrollTo

window.scrollTo(0, 0);

https://www.w3schools.com/jsref/met_win_scrollto.asp

Lists browsersupport for Safari



Related Topics



Leave a reply



Submit