在做mouseenter与mouseleave的兼容时,我们需要用到事件对象的relatedTarget属性
function getRelatedTarget(e) {
var t = e.relatedTarget
if (t) {
return t
}
return e.fromElement === e.target ?
e.toElement :
e.fromElement;
}
String("mouseenter,mouseleave").replace(/\w+/g, function (type) {
eventHooks[type] = function (dom) {
var eventType = type === "mouseenter" ? "mouseover" : "mouseout";
addEvent(dom, eventType, function (e) {
var t = getRelatedTarget(e)
if (!t || (t !== dom && !dom.contains(t))) {
dispatchEvent(e, type, true);
}
});
};
});