2014-12-04 55 views
1

我正在開發需要鼠標滾輪事件的自定義滾動條。這裏是附加到滾動條的jQuery可拖動方法。Mousewheel事件和Jquery Draggable Div

$(this._ScrollBarTrackPiece).draggable({ 
      axis: 'y', 
      containment: "parent", 
      start: function(event,ui){ 
      this.previousPosition = ui.position; 
      }.bind(this), 
      drag: function(event,ui) { 
      if(this.previousPosition.top > ui.position.top){ 
       this.doVerticalStepScroll(this._crosstabScrollBarEventConstants.Up); 
      } else{ 
       this.doVerticalStepScroll(this._crosstabScrollBarEventConstants.Down); 
      } 
      }.bind(this) 
    }); 

但是,我需要掛鉤鼠標滾輪事件來做與jquery方法完全相同的事情。我不知道從哪裏開始,因爲我希望這很簡單,只需將輪子事件綁定到jQuery可拖動方法,並確定它是向上還是向下。

回答

0

你可以用下面這段代碼有一個鼠標滾輪事件

//FF doesn't recognize mousewheel as of FF3.x 
 
var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel"; 
 

 
if (this._ScrollBarTrackPiece.attachEvent) //if IE (and Opera depending on user setting) 
 
    this._ScrollBarTrackPiece.attachEvent("on"+mousewheelevt, doScroll); 
 
else if (this._ScrollBarTrackPiece.addEventListener) //WC3 browsers 
 
    slideshow.addEventListener(mousewheelevt, doScroll, false); 
 

 
var doScroll = function() 
 
{ ... }

謝謝