Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.scrollTo not working in iOS chrome

We are using javascript code to scroll to a div with the given ID. I tried to use

jQuery.animate({scrollTop: number})

window.scrollTo(0, number) 

setTimeout(function() {window.scrollTo(0, number);}, 1000)

I also tried to add #element_id to the url to scroll to the element_id.

None of these options are working. Is there any way to get it to work?

iOS: 9.2.1

Chrome: 48.0.2564.87

http://jsfiddle.net/fXx6c/114/

like image 419
arun15thmay Avatar asked Feb 08 '16 09:02

arun15thmay


People also ask

What is window scrollTo?

Definition and Usage The scrollTo() method scrolls the document to specified coordinates.

How do I scroll down on Windows?

If you look to the right side of your keyboard, you'll see four arrows: up, down, left, and right. You can use the down arrow to scroll down on a web page and the up arrow to scroll back up.

How do you scroll in JavaScript?

To scroll the page with JavaScript, its DOM must be fully built. For instance, if we try to scroll the page with a script in <head> , it won't work. Regular elements can be scrolled by changing scrollTop/scrollLeft . We can do the same for the page using document.


1 Answers

You can use window.scroll() instead. I tested in your jsfiddle and it worked. Usage would be the same as window.scrollTo().

For example: window.scroll(0, 485);

This answer might explain why window.scrollTo doesn't work

like image 63
Allure Web Solutions Avatar answered Sep 30 '22 14:09

Allure Web Solutions