简体   繁体   English

当滚动条出现时,eventlistener / CSS伪类

[英]eventlistener / css pseudo class when scrollbar appears

is there a javascript eventlister or css pseudo class when a scrollbar appears and disappears? 滚动条出现和消失时,是否存在JavaScript eventlister或CSS伪类? For example system Mac OS, the Scrollbars are default hidden, when you start scrolling they do appear. 例如系统Mac OS,滚动条默认为隐藏,当您开始滚动时,滚动条会出现。 Same for Windows Internet Explorer >= 10. I want to know that the scrollbars are appeared and disappeared. 与Windows Internet Explorer> = 10相同。我想知道滚动条是出现还是消失。 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. 但是,当我单击滚动条而不滚动时,计时器将删除docsroll-class,并且我也不知道何时删除doscroll-class的确切时间。

Has any one a better solution / idea? 有没有更好的解决方案/想法?

Thanks Oliver 谢谢奥利弗

No. Scrollbars are implementation dependent. 否。滚动条取决于实现。

The spec says 规格

The scrolling mechanism depends on the UA. 滚动机制取决于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. 因此,该事件将毫无意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM