'Eventlistener / CSS pseudo class when scrollbar appears

Is there a JavaScript eventlistener or CSS pseudo class when a scrollbar appears and disappears? For example system Mac OS, the Scrollbars are default hidden, when you start scrolling they do appear. Same for Windows Internet Explorer >= 10. I want to know that the scrollbars are appeared and disappeared. My first test:

var doscroll = false,
        $html = $('html'),
        timer;
$(window).on('scroll', function () {
    if (!doscroll) {
        doscroll = true;
        $html.addClass('doscroll');
    }
    clearTimeout(timer);
    timer = setTimeout(function () {
        doscroll = false;
        $html.removeClass('doscroll');
    }, 2000);
})

But when I click on the Scrollbar and do not scroll the timer removes the docsroll-class, and I also don’t know the exact time when to remove the doscroll-class.

Has any one a better solution / idea?



Solution 1:[1]

No. Scrollbars are implementation dependent.

The spec says

The scrolling mechanism depends on the UA. The most common mechanism is a scrollbar, but panners, hand cursors, page flickers, etc. are also possible.

Therefore, some implementations have no scrollbars, and some others have but never hide them. Thus that event would make no sense.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Oriol