美文网首页
兼容event函数

兼容event函数

作者: adtk | 来源:发表于2020-02-13 22:33 被阅读0次
        function evnt(event) {

            var evn = event,
                eventDoc,//当前节点的顶层的 document 对象
                doc,//document.documentElement
                body,
                button = evn.button;//鼠标按键值

            evn.target = evn.target || evn.srcElement;

            // Calculate pageX/Y if missing and clientX/Y available
            if (evn.pageX == null && evn.clientX != null) {
                eventDoc = evn.target.ownerDocument || document;//返回当前节点的顶层的 document 对象
                doc = eventDoc.documentElement || eventDoc.body;

                evn.pageX = evn.clientX + (doc.scrollLeft) - (doc.clientLeft);
                evn.pageY = evn.clientY + (doc.scrollTop) - (doc.clientTop);
            }

            if (!evn.preventDefault) {
                evn.preventDefault = function () {
                    this.returnValue = false;//取消发生事件源元素的默认动作
                }
            }

            if (!evn.stopPropagation) {
                evn.stopPropagation = function () {
                    this.cancelBubble = true;//ie冒泡行为
                }
            }

            if (evn.which == null && (evn.charCode != null || evn.keyCode != null)) {
                evn.which = evn.charCode != null ? evn.charCode : evn.keyCode;
            }

            // Add which for click: 1 === left; 2 === middle; 3 === right
            // Note: button is not normalized, so don't use it
            if (!evn.which && button !== undefined) {
                evn.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
            }
            return evn
        };

相关文章

  • 兼容event函数

  • JavaScript兼容

    // 属性的兼容,使用||解决// 方法的兼容,使用if判断解决 event事件获取兼容 注意:event需要逐层...

  • JS事件 Event

    获得event对象兼容性写法 :event || (event = window.event); 获得target...

  • event

    1. 事件对象的获取 var event = event || window.event; // 兼容写法, i...

  • 事件

    如何绑定事件处理函数 1.ele.onxxx = function(event){}兼容性很好,但是一个元素的同一...

  • 事件对象的兼容性问题

    event对象 在IE下可以识别在FF下要以函数的形式 兼容所有的浏览器的写法document.onmousem...

  • 事件对象及实例

    事件对象: event兼容性: 兼容 Chrome IE系列 不兼容FireFox在FF里: ev ...

  • js Event

    1:什么是event? 2:event的兼容写法: 3: 事件源的兼容 4: 获取鼠标在可视窗口的位置 5:获取...

  • 阻止默认事件

    epreventDefault(); window.event.returnvalue = false; 处理兼容...

  • 绑定click事件

    Event 函数 绑定函数至...

网友评论

      本文标题:兼容event函数

      本文链接:https://www.haomeiwen.com/subject/eqdrfhtx.html