T
T
Taras Labiak2016-06-14 04:31:00
safari
Taras Labiak, 2016-06-14 04:31:00

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);

But for some reason only the code works in Chrome and Safari
document.addEventListener('DOMContentLoaded', function () {
    setTimeout(function () {
        document.querySelector('.message:last-of-type').scrollIntoView(false);
    }, 0);
});

Full source code
Is this a WebKit engine bug?
webkit.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rou1997, 2016-06-14
@Rou1997

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).

V
Victor Machalsky, 2016-07-21
@mviktorcom

Hello. Because such a life

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question