Answer the question
In order to leave comments, you need to log in
Why does scrollIntoView work weird in WebKit?
After the page has loaded, I want to scroll to the latest post (works in Firefox and IE11)
document.querySelector('.message:last-of-type').scrollIntoView(false);
document.addEventListener('DOMContentLoaded', function () {
setTimeout(function () {
document.querySelector('.message:last-of-type').scrollIntoView(false);
}, 0);
});
Answer the question
In order to leave comments, you need to log in
It's not a bug, and scrollIntoView has nothing to do with it, it's just that your script starts executing before this DOM element is loaded, so either wait for the event (complete loading), or place the script after the element (parsing and building the DOM goes from top to bottom, head first, then body).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question