3

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

虽然我似乎能够使用 jQuery 之类的事件scrollLeft,但 nicescroll 破坏了中间单击和滚动功能,这本身并没有那么糟糕,但表明其他未知行为也可能被破坏。

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

4

1 回答 1

0

从我的头顶

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;
  }
}) 

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

于 2013-07-25T17:38:44.610 回答