Is there a way to set the scroll position of a window without using scroll () or scrollTo ()?

... the reason I'm asking is because Safari has an error in its implementation of scroll (), which violates my interface.

Imagine the page:

<body>
    <div id="huge" style="width: 4000px; height: 4000px;"></div>
</body>

... so that you get both horizontal and vertical scrollbars. Now, usually when you click the scroll bar, the page scrolls (vertically). For the purposes of our trendy user interface, we don't want this to happen, so we crushed the keyDown event:

window.onkeydown = function(e) {
    if(e.keyCode == 32)
    {
        return false;
    }
};

This works fine if we haven't decided that instead of preventing scrolling altogether, we want to have our own custom scroll behavior:

window.onkeydown = function(e) {
    if(e.keyCode == 32)
    {
        window.scroll(foo, bar); // Causes odd behavior in Safari
        return false;
    }
};

(Chrome, Firefox) . Safari , , , .

, OTHER, , ; , .

, , 1000 , .

, . , , , - Javascript - . .

+3
2

document.documentElement.scrollTop = ... ( document.body ).

-1

, , . document.location (, #top, #div50 - ) .

+2

Source: https://habr.com/ru/post/1795171/


All Articles