JavaScript uses array to implement tab menu Toggle Effect _ navigation Menu

Source: Internet
Author: User
Recently wrote a tab menu, this is also a product of web2.0, no technical content, practice practicing just.

The following is the HTML structure of the tab menu:
<div id= "A" ><div id= "head" ><span id= "tab1" >vhc</span><span id= "TaB2" >dsdfd</span >..........................<span id= "blank" ></span></div><div id= "Body" ></div> </div>
The TAB1,TAB2 is the content, the blank is the remainder. The body is the tab label corresponding to the content.

Here's the JavaScript code:
Copy Code code as follows:

sx.activex.tabmenu={
Create:function (t) {
var a=document.createelement ("div");
var head=document.createelement ("div");
var body=document.createelement ("div");
var blank=document.createelement ("span");
A.style.height= "200px";
A.style.width= "300px";
A.style.border= "1px red solid";
Head.style.height= "15%";
Head.style.overflow= "hidden";
Head.style.width= "100%";
blank.style.width=100-20*t.length+ "%";
Blank.style.height= "100%";
Blank.style.borderbottom= "1px red solid";
Blank.style.lineheight=parseint (a.style.height) *0.15+ "px";
BODY.INNERHTML=T[0][1];
Body.style.height= "85%";
Body.style.padding= "10px";
Body.style.border= "1px red solid";
body.style.bordertop= "0px";
for (Var i=0;i<t.length;i++) {
var tab=document.createelement ("span");
Tab.style.border= "1px red solid";
Tab.style.width= "20%";
Tab.style.lineheight=parseint (a.style.height) *0.15+ "px";
tab.style.textalign= "center";
Tab.style.height= "100%";
Tab.style.backgroundcolor= "Yellow";
Tab.style.cursor= "Hand";
TAB.INNERHTML=T[I][0];
Tab.onclick=function (R) {
return function () {
for (var i1 in Head.all) {
if (head.all[i1]!=this && head.all[i1].tagname== "SPAN")
Head.all[i1].style.borderbottom= "1px red solid";
this.style.borderbottom= "0px";

}
BODY.INNERHTML=T[R][1];
}
} (i);
Head.appendchild (tab);
}
head.firstchild.style.borderbottom= "0px";
Head.appendchild (blank);
A.appendchild (head);
A.appendchild (body);
return A;
}
}

The incoming parameter t is a two-dimensional array, which is the form of a tag topic and the contents of the label, called as follows:
Copy Code code as follows:

<title>untitled document</title>
<body>

<script src= "Kongjian.js" ></script>

<script>
var a=sx.activex.tabmenu.create ([["ASD", "Wewfrwefwe"],["we", "DSFSDFSDF"]]);

Document.body.appendChild (a);

</script>
</body>

Almost finished, interested friends can go to the test.

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.