Code _javascript tips for JavaScript-compatible FF Onmouseenter and OnMouseLeave

Source: Internet
Author: User

IE under the onmouseenter and OnMouseLeave to solve.
Unfortunately, FF is not. I think again, why such a good function, why FF do not quote it?
There are IE in the onpropertychange, ah, FF did not ...

A section of JS is introduced in the contrast example to accommodate FF Onmouseenter and OnMouseLeave. :
Copy Code code as follows:

var xb =
{
Evthash: [],

Iegetuniqueid:function (_elem)
{
if (_elem = = window) {return ' Thewindow ';}
else if (_elem = = document) {return ' thedocument ';}
else {return _elem.uniqueid;}
},

Addevent:function (_elem, _evtname, _FN, _usecapture)
{
if (typeof _elem.addeventlistener!= ' undefined ')
{
if (_evtname = = ' MouseEnter ')
{_elem.addeventlistener (' mouseover ', Xb.mouseenter (_FN), _usecapture);}
else if (_evtname = ' MouseLeave ')
{_elem.addeventlistener (' mouseout ', Xb.mouseenter (_FN), _usecapture);}
Else
{_elem.addeventlistener (_evtname, _FN, _usecapture);}
}
else if (typeof _elem.attachevent!= ' undefined ')
{
var key = ' {fnkey::obj_ ' + Xb.iegetuniqueid (_elem) + ':: Evt_ ' + _evtname + ':: Fn_ ' + _fn + '} ';
var f = Xb.evthash[key];
if (typeof F!= ' undefined ')
{return;}

f = function ()
{
_fn.call (_elem);
};

Xb.evthash[key] = f;
_elem.attachevent (' on ' + _evtname, f);

Attach Unload event to the windows to clean up possibly IE memory leaks
Window.attachevent (' OnUnload ', function ()
{
_elem.detachevent (' on ' + _evtname, f);
});

key = null;
f = null; /* DON ' t null this out, or we won ' t is able to detach it * *
}
Else
{_elem[' on ' + _evtname] = _FN;}
},

Removeevent:function (_elem, _evtname, _FN, _usecapture)
{
if (typeof _elem.removeeventlistener!= ' undefined ')
{_elem.removeeventlistener (_evtname, _FN, _usecapture);}
else if (typeof _elem.detachevent!= ' undefined ')
{
var key = ' {fnkey::obj_ ' + Xb.iegetuniqueid (_elem) + ':: evt ' + _evtname + ':: Fn_ ' + _fn + '} ';
var f = Xb.evthash[key];
if (typeof F!= ' undefined ')
{
_elem.detachevent (' on ' + _evtname, f);
Delete Xb.evthash[key];
}

key = null;
f = null; /* DON ' t null this out, or we won ' t is able to detach it * *
}
},

Mouseenter:function (_PFN)
{
return function (_EVT)
{
var reltarget = _evt.relatedtarget;
if (this = = Reltarget | | xb.isachildof (this, reltarget))
{return;}

_pfn.call (this, _evt);
}
},

Isachildof:function (_parent, _child)
{
if (_parent = = _child) {return false};

while (_child && _child!= _parent)
{_child = _child.parentnode;}

return _child = = _parent;
}
};
This article comes from cssrain.cn original link: http://www.cssrain.cn/article.asp?id=952

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.