实现漂亮的滚动条,并保留本地功能

Implement nicely styled scroll bars, and retain native functionality

本文关键字:保留 功能 漂亮 滚动条 实现      更新时间:2023-09-26

我正在使用库:https://code.google.com/p/jquery-nicescroll/downloads/detail?name=jquery.nicescroll.340.zip&can=2&q=

虽然我似乎能够使用像jQuery的scrollLeft和喜欢的事件,nicescroroll打破了中间点击和滚动功能,这本身并不是那么糟糕,但表明其他未知的行为也可能被打破。

是否有任何库/方法来实现漂亮的滚动条,但与本机功能?

off the top of my head

var MIDDLE_CLICK = 2;
var clicking = [];
var moveInterval = undefined;
var lastY = undefined;
$("#nicely_scrolled_element").mousedown(function(e){
  clicking[e.which] = true
  startY = lastY = e.pageY;
  // default behavior is every so often scroll the page
  // we base it on how far they were last from the start
  moveInterval = setInterval(function(){
    $el = $('#nicely_scrolled_element');
    $el.scrollTop($el.scrollTop() + lastY - startY);
  }, 500);
})
// they may mouse up elsewhere so we use window this time
$(window).mouseup(function(e){
  clicking[e.which] = false
  clearInterval(moveInterval);
})
// remember where they moved to
$(window).mousemove(function(e){
  if(clicking[MIDDLE_CLICK]){
    lastY = e.pageY;
  }
}) 

这是未经测试的,我只是把它写出来。应该管用吗?