I use:
var el = document.getElementById("centd");
el.scrollIntoView(true);
to scroll to specific position. In every browser it works fine, but in Chrome when the page is loaded it scrolls to that point, but after a second or two (when the page is finished loading) it scrolls back to start.
Make sure all your JavaScript code is run after your page completes loading:
document.addEventListener('DOMContentLoaded', function() {
// your code here
}, false);
Or if you're using jQuery:
$(document).ready(function(){
// your code
});
This will make sure that your code runs the way you intend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With