JavaScript encapsulates a tab effect source sharing _javascript Tips

Source: Internet
Author: User

The effect chart is as follows:

View Demo Source Download

HTML code

<! DOCTYPE html>

JS Code

function TabPanel (param) {var defaultindex=param["default"]| |,//settings displayed page panelobj=param["Panel"],//set tab container defalutclass=param["Defalutstyle"]| | "",/Set the Normal style of the tab item hoverclass=param["Hoverstyle"]| | " Hover ",//Set mouse to Move to tab menu item style Currentindex=defaultindex, menus=_$ (panelobj). getElementsByTagName (" ul ") [].
 getElementsByTagName ("Li"), contents=_$ (panelobj). getElementsByTagName ("ul") [].getelementsbytagname ("Li"),
 Menunumber=menus.length, hidden= "hidden";
 for (Var i=;i<menunumber;i++) {_setclass (contents[],hoverclass);
 _setclass (Contents[i],hidden);
 _setclass (Menus[i],defalutclass);
 (function (i) {menus[i].onmouseover=function () {var old=menus[currentindex];
 _setclass (Old,defalutclass);
 _setclass (Contents[currentindex],hidden);
 var cur=menus[i];
 _setclass (Cur,hoverclass);
 _setclass (Contents[i], "");
 }) (i);
 } _setclass (Menus[currentindex],hoverclass);
 _setclass (Contents[currentindex], "");
 Convenience functions function _setclass (obj,classname) {obj.classname=classname}function _$ (OID) {return typeof (oid) = = "string"? document.getElementById (OID): OID}}


CSS Code

#tab {border:px solid #ccc;}
#tab. tab-bd{border-top:none;margin:auto;padding:px;text-align:left;height:px;position:relative}
. tab-nav{ Margin:auto;padding:;background: #eee; height:px;}
. Tab-nav Li{display:inline;list-style:none outside None;width:px;height:px;float:left;line-height:px;text-align: Center}
. Tab-nav li a{color:#;d isplay:inline-block}
tab-nav li A:hover,.tab-nav li.hover; Background: #fff; color:#;d Isplay:block; }
. Hidden{display:none}
Related Article

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: 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.