Mousewheel事件和Jquery Draggable Div

时间:2014-12-04 01:40:48

标签: jquery draggable mousewheel

我正在开发一个需要鼠标滚轮事件的自定义滚动条。这是附加到滚动条的jquery draggable方法。

 $(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 draggable方法并确定它是向上还是向下一样简单。

1 个答案:

答案 0 :(得分: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()
{ ... }

谢谢,