滚动条显示在滚动条上

时间:2014-11-22 19:44:07

标签: javascript jquery html css

我最近看到一个网站上有一个隐藏的滚动条,它出现在滚动条上。这也可能是因为它是一个滑溜的网格。我能够控制特定于div的滚动条CSS但无法通过javascript控制它。到目前为止,我的脚本非常简单:

$('#mydiv').scroll(function(){
    $('#mydiv::-webkit-scrollbar').fadeIn(500);
    //I've also tried .css() above and tried the .hover event as well
})

我的div和滚动条css:

#mydiv{overflow-x: hidden; overflow-y: auto; height: 80%; width: 100%;}
#mydiv::-webkit-scrollbar{display: none;}

有没有办法在滚动时显示滚动条?我已经知道如何通过更改css中:hover的溢出来控制悬停。

1 个答案:

答案 0 :(得分:1)

不需要插件,试试这个:

JS:

$(window).bind('mousewheel', function(e) {
  var el = $('body');
  el.css('overflow-y', 'scroll');
  if (el[0].hideScroll) clearTimeout(el[0].hideScroll);
  el[0].hideScroll = setTimeout(function() {
    el.css('overflow-y', 'hidden');
  }, 500);
});

CSS:

body {
  overflow-y: hidden;
}