Onmouseover and onmouseout functions using JS

Source: Internet
Author: User

First, define the style used for onmouseover and onmouseout.

 

<Style type = "text/CSS">

. Actionbtnin
{
Background: url('button_in.jpg ') Repeat-x
}

. Actionbtnout
{
Background: url('button_out.jpg ') Repeat-x

}

</Style>

 

Copy the script to the master page.

 

<SCRIPT type = "text/JavaScript">
(Function (){
Function addevent (ELM, evtype, FN, usecapture ){
If (ELM. addeventlistener ){
Elm. addeventlistener (evtype, FN, usecapture );
Return true;
}
Else if (ELM. attachevent ){
VaR r = Elm. attachevent ('on' + evtype, FN );
Return R;
}
Else {
Elm ['on' + evtype] = FN;
}
}

Function getelementsbyclassname (classname, Tag, elm ){
VaR testclass = new Regexp ("(^ | // s)" + classname + "(// s | $ )");
VaR tag = tag | "*";
VaR elm = elm | document;
VaR elements = (TAG = "*" & Elm. All )? Elm. ALL: Elm. getelementsbytagname (TAG );
VaR returnelements = [];
VaR current;
VaR length = elements. length;
For (VAR I = 0; I <length; I ++ ){
Current = elements [I];
If (testclass. Test (current. classname )){
Returnelements. Push (current );
}
}
Return returnelements;
}

Function moverhandler (e ){
VaR EVT = E | window. event;
VaR El = e.tar GET | E. srcelement;

If (El. classname. indexof ("actionbtnin") =-1 & El. classname. indexof ("actionbtnout") =-1)
El. classname + = ("actionbtnin ");

El. classname = El. classname. Replace (/actionbtnout/ig, "actionbtnin ");
}

Function mouthandler (e ){
VaR EVT = E | window. event;
VaR El = e.tar GET | E. srcelement;

If (El. classname. indexof ("actionbtnin") =-1 & El. classname. indexof ("actionbtnout") =-1)
El. classname + = ("actionbtnout ");

El. classname = El. classname. Replace (/actionbtnin/ig, "actionbtnout ");
}

VaR objlistmainbutton = getelementsbyclassname ("mainbutton ");
VaR objlistmainbutton150 = getelementsbyclassname ("mainbutton150 ");
VaR objlistmainbutton50 = getelementsbyclassname ("mainbutton50 ");

For (VAR I = 0; I <objlistmainbutton. length; I ++ ){
VaR curobj = objlistmainbutton [I];
(Function (){
Addevent (curobj, "Mouseover", moverhandler );
Addevent (curobj, "mouseout", mouthandler );
})();
}

For (VAR I = 0; I <objlistmainbutton150.length; I ++ ){
VaR curobj = objlistmainbutton150 [I];
(Function (){
Addevent (curobj, "Mouseover", moverhandler );
Addevent (curobj, "mouseout", mouthandler );
})();
}

For (VAR I = 0; I <objlistmainbutton50.length; I ++ ){
VaR curobj = objlistmainbutton50 [I];
(Function (){
Addevent (curobj, "Mouseover", moverhandler );
Addevent (curobj, "mouseout", mouthandler );
})();
}

})();
</SCRIPT>

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.