Common javascript sliding door tab class

Source: Internet
Author: User

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead> <meta http-equiv =" content-Type "content =" text/html; charset = gb2312 "/> <title> sliding door General JS </title> <style type =" text/css "> </style> </pead> <body> sliding door encapsulation class effect preview <ul class = "scrollUl"> <li class = "sd01" id = "m01"> sliding door </li> <li class = "sd02" id = "m02"> sliding door </li> <li class = "sd02" id = "m03"> sliding door </li> <li class = "sd02" id = "m04"> sliding door </ li> <li class = "sd02" id = "m05"> sliding door </li> </ul> Layer 1 content Layer 2 content Layer 3 content Layer 4 content layer 5 content <ul class = "scrollUl"> <li class = "sd01" id = "mm01"> sliding door </li> <li class = "sd02" id = "mm02"> sliding door </li> <li class = "sd02" id = "mm03"> sliding door </li> <li class = "sd02" id = "mm04"> sliding door </li> <li class = "sd02" id = "mm05"> sliding door </li> </ul> Layer 1 content Layer 2 content Layer 3 content Layer 4 content layer 5 content <ul class = "scrollUl"> <li class = "sd01" id = "mmm01"> sliding door </li> <li class = "sd02" id = "mmm02"> sliding door </li> <li class = "sd02" id = "mmm03"> sliding door </li> <li class = "sd02" id = "mmm04"> sliding door </li> <li class = "sd02" id = "mmm05"> sliding door </li> </ul> Layer 1 content Layer 2 content Layer 3 content Layer 4 content layer 5 content </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Source code:Copy codeThe Code is as follows:

Function scrollDoor (){
}
ScrollDoor. prototype = {
Sd: function (menus, divs, openClass, closeClass ){
Var _ this = this;
If (menus. length! = Divs. length)
{
Alert ("the number of menu layers is different from the number of content layers! ");
Return false;
}
For (var I = 0; I <menus. length; I ++)
{
_ This. $ (menus [I]). value = I;
_ This. $ (menus [I]). onmouseover = function (){

For (var j = 0; j <menus. length; j ++)
{
_ This. $ (menus [j]). className = closeClass;
_ This. $ (divs [j]). style. display = "none ";
}
_ This. $ (menus [this. value]). className = openClass;
_ This. $ (divs [this. value]). style. display = "block ";
}
}
},
$: Function (oid ){
If (typeof (oid) = "string ")
Return document. getElementById (oid );
Return oid;
}
}

Usage:

1. Introduce the above Code to your page
Copy codeThe Code is as follows:

<Script type = "text/javascript" src = "scrollDoor. js"> </script>

2. Add the following code before the "<body>" tag on the page:

Copy codeThe Code is as follows:
<Script type = "text/javascript">
Var SDmodel = new scrollDoor ();
SDmodel. sd ([menu id array], [display layer id array], "menu trigger class", "menu close class ");
SDmodel. sd ([menu id array 2], [display layer id array 2], "menu trigger class", "menu close class ");
SDmodel. sd ([menu id array 3], [display layer id array 3], "menu trigger class", "menu close class ");
</Script>

The parameters in the sd method are:

Parameter 1 [menu id array]: the id of the sliding menu
Parameter 2 [Content id array]: Display and hide the id of the sliding content Layer
Parameter 3 "menu trigger class": class of the menu with the mouse sliding door
Parameter 4 "menu closure class": class for sliding menu with the mouse out
3. There are several sliding doors on the page to call the sd function several times. You only need to change the parameters of the sd call, as shown in the code above.

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.