ScrollTo / ScrollBy in Chrome

298 Views Asked by At

Do any of you know why scrollTo and scrollBy methods in Chrome are not working. In other browsers eg Firefox it works. I can fix the issue by adding a setTimeout. An eventListener like load or DOMContentloaded is not working. Thanks and VG.

<script>
scrollTo(0,200); // does not work
setTimeout(function a() {scrollTo(0,200);},1); //works.
</script>
1

There are 1 best solutions below

0
Maged Ibrahim On

According to Mark Ni's Comment in JavaScript issue with scrollTo() in Chrome issue:

Chrome is so fast that your scrollTo() action fires before Chrome's default scroll to html anchor event.