//添加事件兼容 function addEvent(obj, type, fn) { if (obj.addEventListener) { obj.addEventListener(type, fn); } else if (obj.attachEvent) { obj.attachEvent('on' + type, fn); } } //移除事件 function removeEvent(obj, type, fn) { if (obj.removeEventListener) { obj.removeEventListener(type, fn); } else if (obj.detachEvent) { obj.detachEvent('on' + type, fn); } } //获取relatedTarget function getTarget(evt) { var e = evt || window.event; if (e.srcElement) { if (e.type == 'mouseover') { return e.fromElement; } else if (e.type == 'mouseout') { return e.toElement; } } else if (e.relatedTarget) { return e.relatedTarget; } } //阻止事件冒泡 function stopBubble(e) { var e = evt || window.event; if (e.stopPropagation ) { e.stopPropagation(); }else { e.cancelBubble = true; } } //阻止默认事件 function preDef(evt) { var e = evt || window.event; if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } } //获取wheelDelta function getWD(evt) { var e = evt || window.event; if (e.wheelDelta) { return e.wheelDelta; } else if (e.detail) { return -evt.detail * 30; } }