Code of onmouseenter and onmouseleave compatible with FF in Javascript

Source: Internet
Author: User


In IE, there are onmouseenter and onmouseleave.
Unfortunately, FF does not. I want to explain again, why does FF not reference such a good function?
There is also onpropertychange in IE, ah, FF, none...

A js section is introduced in the comparison example to be compatible with FF's onmouseenter and onmouseleave .:CopyCodeThe Code is 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 window 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 be 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 be 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 articleArticleSource of 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.