Home >Web Front-end >JS Tutorial >js implements simple TAB sliding door effect code_javascript skills
The example in this article describes the simple TAB sliding door effect code implemented in js. Share it with everyone for your reference. The details are as follows:
This is a sliding door code, simple TAB, simple mouse navigation effect, which you may often see. When the mouse is placed on the main menu, the content in the frame below will change accordingly, and the mouse does not need to be clicked. You only need to slide it up to switch content, like a door, so sometimes others call it a "sliding door" menu.
The operation effect is as shown below:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-tab-simple-cha-style-codes/
The specific code is as follows:
<html> <head> <title>简洁TAB</title> <script type="text/javascript"> function nTabs(thisObj, Num) { if (thisObj.className == "active") return; var tabObj = thisObj.parentNode.id;//赋值指定节点的父节点的id名字 var tabList = document.getElementById(tabObj).getElementsByTagName("li"); for (i = 0; i < tabList.length; i++) {//点击之后,其他tab变成灰色,内容隐藏,只有点击的tab和内容有属性 if (i == Num) { thisObj.className = "active"; document.getElementById(tabObj + "_Content" + i).style.display = "block"; } else { tabList[i].className = "normal"; document.getElementById(tabObj + "_Content" + i).style.display = "none"; } } } </script> <style type="text/css"> * { margin: 0; padding: 0; list-style: none; font-size: 14px; } .nTab { width: 500px; height:200px; margin: 20px auto; border: 1px solid #333; overflow: hidden; } .none { display: none; } .nTab .TabTitle li { float: left; cursor: pointer; height: 35px; line-height: 35px; font-weight: bold; text-align: center; width: 124px; } .nTab .TabTitle li a { text-decoration: none; } .nTab .TabTitle .active { background-color:blue; color: #336699; } .nTab .TabTitle .normal { color: #F1AC1C; } .nTab .TabContent { clear: both; overflow: hidden; background: #fff; padding: 5px; display: block; height:100px; } </style> </head> <body> <div class="nTab"> <div class="TabTitle"> <ul id="myTab"> <li class="active" onmouseover="nTabs(this,0);">ASP</li> <li class="normal" onmouseover="nTabs(this,1);">PHP2</li> <li class="normal" onmouseover="nTabs(this,2);">PHP3</li> <li class="normal" onmouseover="nTabs(this,3);">PHP4</li> </ul> </div> <div class="TabContent" > <div id="myTab_Content0"> 第一块内容</div> <div id="myTab_Content1" class="none"> 第二块内容</div> <div id="myTab_Content2" class="none"> 第三块内容</div> <div id="myTab_Content3" class="none"> 第四块内容</div> </div> </div> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming.