博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jquery mousewheel
阅读量:5315 次
发布时间:2019-06-14

本文共 2823 字,大约阅读时间需要 9 分钟。

(function($) {    var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'];    var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'];    var lowestDelta, lowestDeltaXY;    if ($.event.fixHooks) {        for (var i = toFix.length; i;) {            $.event.fixHooks[toFix[--i]] = $.event.mouseHooks        }    }    $.event.special.mousewheel = {        setup: function() {            if (this.addEventListener) {                for (var i = toBind.length; i;) {                    this.addEventListener(toBind[--i], handler, false)                }            } else {                this.onmousewheel = handler            }        },        teardown: function() {            if (this.removeEventListener) {                for (var i = toBind.length; i;) {                    this.removeEventListener(toBind[--i], handler, false)                }            } else {                this.onmousewheel = null            }        }    };    $.fn.extend({        mousewheel: function(fn) {            return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel")        },        unmousewheel: function(fn) {            return this.unbind("mousewheel", fn)        }    });    function handler(event) {        var orgEvent = event || window.event,        args = [].slice.call(arguments, 1),        delta = 0,        deltaX = 0,        deltaY = 0,        absDelta = 0,        absDeltaXY = 0,        fn;        event = $.event.fix(orgEvent);        event.type = "mousewheel";        if (orgEvent.wheelDelta) {            delta = orgEvent.wheelDelta        }        if (orgEvent.detail) {            delta = orgEvent.detail * -1        }        if (orgEvent.deltaY) {            deltaY = orgEvent.deltaY * -1;            delta = deltaY        }        if (orgEvent.deltaX) {            deltaX = orgEvent.deltaX;            delta = deltaX * -1        }        if (orgEvent.wheelDeltaY !== undefined) {            deltaY = orgEvent.wheelDeltaY        }        if (orgEvent.wheelDeltaX !== undefined) {            deltaX = orgEvent.wheelDeltaX * -1        }        absDelta = Math.abs(delta);        if (!lowestDelta || absDelta < lowestDelta) {            lowestDelta = absDelta        }        absDeltaXY = Math.max(Math.abs(deltaY), Math.abs(deltaX));        if (!lowestDeltaXY || absDeltaXY < lowestDeltaXY) {            lowestDeltaXY = absDeltaXY        }        fn = delta > 0 ? 'floor': 'ceil';        delta = Math[fn](delta / lowestDelta);        deltaX = Math[fn](deltaX / lowestDeltaXY);        deltaY = Math[fn](deltaY / lowestDeltaXY);        args.unshift(event, delta, deltaX, deltaY);        return ($.event.dispatch || $.event.handle).apply(this, args)    }}));

 

转载于:https://www.cnblogs.com/yc-code/p/5089007.html

你可能感兴趣的文章
VS2010 NDoc的插件工具
查看>>
javac compiling error ( mising package)
查看>>
html-盒子模型及pading和margin相关
查看>>
vijos p1347(最大乘积(整数划分?))(25—100分)
查看>>
jq select操作全集
查看>>
排序算法-C++实现
查看>>
代码优化从数据库里查数据
查看>>
机器学习------精心总结
查看>>
python自动化测试-D6-学习笔记之一(常用模块补充datetime模块)
查看>>
javascript:with的用法以及延长作用域链
查看>>
第2课:关闭被黑客扫描的端口
查看>>
redis集群报Jedis does not support password protected Redis Cluster configurations异常解决办法...
查看>>
文件传输基础——Java IO流
查看>>
一头扎进Node(三) - File System
查看>>
windows 下 MyEclipse 逆向工程生成hiberate 对应配置文件以及 javaBean。
查看>>
SharePoint 2010 master page 控件介绍(5):其他
查看>>
SQL对Xml字段的操作
查看>>
解决WP7的32位图像渐变色色阶问题
查看>>
centos安装与配置R语言
查看>>
MyEclipse6.5配置反编译插件
查看>>