Last active
October 19, 2016 03:29
-
-
Save tonyc726/87d02cd6c14a22c2d0bc to your computer and use it in GitHub Desktop.
Revisions
-
tonyc726 revised this gist
Oct 19, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,7 @@ var EventUtil = { if (document.createEventObject){ // IE浏览器支持fireEvent方法 var evt = document.createEventObject(); return ele.fireEvent('on'+evType, evt); } else{ // 其他标准浏览器使用dispatchEvent方法 -
tonyc726 revised this gist
Oct 19, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,14 +52,14 @@ var EventUtil = { if (document.createEventObject){ // IE浏览器支持fireEvent方法 var evt = document.createEventObject(); return ele.fireEvent('on'+evType, evt) } else{ // 其他标准浏览器使用dispatchEvent方法 var evt = document.createEvent( 'HTMLEvents' ); // initEvent接受3个参数: // 事件类型,是否冒泡,是否阻止浏览器的默认行为 evt.initEvent(evType, enableCapture, enableDefault); return !ele.dispatchEvent(evt); } -
tonyc726 revised this gist
Oct 19, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,15 +52,15 @@ var EventUtil = { if (document.createEventObject){ // IE浏览器支持fireEvent方法 var evt = document.createEventObject(); return ele.fireEvent('on'+event,evt) } else{ // 其他标准浏览器使用dispatchEvent方法 var evt = document.createEvent( 'HTMLEvents' ); // initEvent接受3个参数: // 事件类型,是否冒泡,是否阻止浏览器的默认行为 evt.initEvent(event, enableCapture, enableDefault); return !ele.dispatchEvent(evt); } }, -
tonyc726 revised this gist
Oct 19, 2016 . No changes.There are no files selected for viewing
-
tonyc726 revised this gist
Oct 19, 2016 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,11 +43,11 @@ var EventUtil = { } }, dispatchHandler: function (ele, evType, enableCapture, enableDefault) { // 默认禁用事件冒泡 enableCapture = enableCapture || false; // 默认禁用浏览器的默认行为 enableDefault = enableDefault || false; if (document.createEventObject){ // IE浏览器支持fireEvent方法 @@ -59,7 +59,7 @@ var EventUtil = { var evt = document.createEvent( 'HTMLEvents' ); // initEvent接受3个参数: // 事件类型,是否冒泡,是否阻止浏览器的默认行为 evt.initEvent(event, enableCapture, enableDefault); return !element.dispatchEvent(evt); } -
tonyc726 revised this gist
Oct 19, 2016 . No changes.There are no files selected for viewing
-
tonyc726 revised this gist
Oct 19, 2016 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,29 @@ var EventUtil = { ele["on" + evType] = fn; } }, dispatchHandler: function (ele, evType, disableCapture, disableDefault) { // 默认禁用事件冒泡 disableCapture = !!disableCapture || true; // 默认禁用浏览器的默认行为 disableDefault = !!disableDefault || true; if (document.createEventObject){ // IE浏览器支持fireEvent方法 var evt = document.createEventObject(); return element.fireEvent('on'+event,evt) } else{ // 其他标准浏览器使用dispatchEvent方法 var evt = document.createEvent( 'HTMLEvents' ); // initEvent接受3个参数: // 事件类型,是否冒泡,是否阻止浏览器的默认行为 evt.initEvent(event, disableCapture, disableDefault); return !element.dispatchEvent(evt); } }, removeHandler: function (ele, evType, fn) { if (ele.removeEventListener) { ele.removeEventListener(evType, fn); -
tonyc726 revised this gist
Jun 4, 2014 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ // 简单的通用事件方法 // http://www.imooc.com/wenda/detail/4603 var EventUtil = { getEvent: function (e) { return e || window.event; -
tonyc726 created this gist
Jun 4, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ var EventUtil = { getEvent: function (e) { return e || window.event; }, getTarget: function (e) { return e.target || e.srcElement; }, preventDefault: function (e) { if (e && e.preventDefault) { e.preventDefault(); } else { window.event.returnValue = false; } }, stopPropagation: function (e) { if (e && e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }, addHandler: function (ele, evType, fn, useCapture) { // 默认使用事件冒泡 useCapture = useCapture || false; if (ele.addEventListener) { ele.addEventListener(evType, fn, useCapture); } else if (ele.attachEvent) { ele.attachEvent("on" + evType, function () { // fn中的this指向ele对象:ie的问题 fn.call(ele); }); } else { ele["on" + evType] = fn; } }, removeHandler: function (ele, evType, fn) { if (ele.removeEventListener) { ele.removeEventListener(evType, fn); } else if (ele.detachEvent) { ele.detachEvent("on" + evType, fn); } else { ele["on" + evType] = null; } } };