JS Code
(Function (w) {//Tab Objectfunction Tab (config) {//define variables to prevent variable contamination This. tabmenus=NULL; This. tabmains=NULL; if(config) { This. _init (config); } } //Add properties to the prototype to prevent memory duplication creationTab.prototype={_init:function (config) {//initializing elements This. initelements (config); This. Initevent (); if(Config.auto) { This. AutoPlay (); }}, Initelements:function (config) {vartabmenu=document.getElementById (Config.tabmenu); vartabmain=document.getElementById (Config.tabmain); This. tabmenus=Tabmenu.children; This. tabmains=Tabmain.children; }, Initevent:function () { for(varI=0;i< This. tabmenus.length;i++){ varLi= This. Tabmenus[i]; Li.index=i; //defines the this variable store, which can be called by the closure environment varthat= This; Li.onclick=function () {That.change ( This); }}}, Change:function (tabmenu) { for(varI=0;i< This. tabmenus.length;i++){ This. tabmenus[i].classname=""; This. tabmains[i].classname="Main"; } tabmenu.classname="Active"; This. tabmains[tabmenu.index].classname+="Select"; }, Autoplay:function () {varindex=0; varthat= This; SetInterval (function () {index++; if(index>=that.tabMenus.length) {Index=0; } that.change (That.tabmenus[index]); }, -); } } //exposing a plugin to Windowsw.tab=Tab;}) (window)
HTML code
<! DOCTYPE html>"en">"UTF-8"> <title>Title</title> <link rel="stylesheet"Type="Text/css"href="Tab.css">class="wrapper"> <ulclass="Tab"Id="Menu"> <liclass="Active"> International Brands <span> </span></li> <li> National makeup brand <span> </span></li> &L T;li> Cleaning Supplies <span> </span></li> <li> men's Boutique </li> </ul> <divclass=" Products"Id="Main"> <divclass="Main Select"><a href="#">"imgs/guojidapai.jpg"></a></div> <divclass="Main"><a href="#">"imgs/guozhuangmingpin.jpg"></a></div> <divclass="Main"><a href="#">"imgs/qingjieyongpin.jpg"></a></div> <divclass="Main"><a href="#">"imgs/nanshijingpin.jpg"></a></div> </div> </div></body><script type="Text/javascript"Src="Tab.js"></script><script>vartb=NewTab ({tabmenu:"Menu", Tabmain:"Main", Auto:true });</script>
CSS Code
Html,body,ul,li {margin:0; padding:0; } ul{List-Style:none;} . wrapper {margin:0Auto; width:1000px; height:475px; Margin-top:100px;} . wrapper. tab {width:320px; height:36px; border:1px solid #ddd; Border-bottom:0; } . wrapper. tab li{float: Left; width:80px; height:34px; Line-height:34px; Cursor:pointer; Text-Align:center; Border-top:4px solid #fff; position:relative; }. Wrapper. tab. active{Border-top:4px solid Red;} . wrapper. tab span{width:1px; height:14px; Background-color: #ddd; Position:absolute; right:0px; top:10px; Overflow:hidden; }. Wrapper. products{width:1002px; height:476px; border:1px solid #ddd; }. Wrapper. products. main{float: Left; Display:none; }. Wrapper. Products.Select{display:block;}
JS Plugin programming-tab Box