首頁 >web前端 >js教程 >Jquery增加滑鼠中間功能mousewheel的實例代碼_jquery

Jquery增加滑鼠中間功能mousewheel的實例代碼_jquery

WBOY
WBOY原創
2016-05-16 17:23:241255瀏覽

複製代碼代碼如下:

(function ($) {
    var types = ['DOMMouseScroll', 'mousewheel'];
    $.event.special.mousewheel = {
        set                for (var i = types .length; i;) {
                   this.addEventListener(types[--i], handler,           } else {
                this.onmouse輪子= 處理程序;
;
; }
        },
        拆解: function () {
           for (var i = types.length; i;) {
                   this.removeEventListener(類型[-- i], handler, false);
                }
         usewheel = null;
           }
        }
    };
.   }
    };
.  extend({
        滑鼠滾輪:函數(fn) {
            return fn ?( },
        unmousewheel:函數(fn) {
            return this.unbind("mousewheel", fn);
        }
  );
    函式處理程序(事件){
        var orgEvent = 事件|| window.event, args = [].slice.call(arguments, 1), delta = 0, returnValue = , deltadelta = 0;
        event = $.event.fix(orgEvent);
        event.type = "mousewheel";        if (event.originalEvent.detail) { delta = -event.originalEvent.detail / 3 🠎>     deltaY = delta;

        // Gecko
        if (orgEvent.axis !== undefined && 0;
            deltaX = -1 * delta;
        }
        // Webkit
        if (orgEvent.wheelattaY !== 錯誤    if (orgEvent.wheelDeltaX !== undefined) { deltaX = - 1 * orgEvent.wheelDeltaX / 120; }
        // 將event 與delta 加到參數前面
        args.unshift(event, deleventta, .X     args.unshift(event, deleventta, )X  handle.apply( this, args);
    }
})(jQuery);

呼叫:
$(document).mousewheel(function (e,detail) {

}


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn