Home  >  Article  >  Web Front-end  >  JS implementation method to change sliding door to tab

JS implementation method to change sliding door to tab

不言
不言Original
2018-07-02 14:08:132143browse

This article mainly introduces the JS implementation method of changing sliding doors into tabs (requiring mouse clicks), involving JavaScript page element traversal and style replacement related techniques, and then through onmouseover and onclick, sliding doors and onclick can be realized respectively. There are two effects of tabs. Friends who need it can refer to

. This article describes the implementation method of changing sliding doors into tabs (requires mouse click) using JS. Share it with everyone for your reference. The details are as follows:

As we all know, sliding doors and tabs are almost the same in terms of layout and structure. The only difference is the triggering method. This is determined by JavaScript. Generally speaking, it is to change onmouseover to Just click on. This tab used to be a popular sliding door, but now it has been changed to a tab. Let’s take a look at the difference.

The screenshot of the running effect is as follows:

The specific code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>滑动门改为选项卡</title>
<style>
*{
padding:0;margin:0;
font-size:12px;
}
#main{
margin:20px;
}
ul{
width:600px;
}
#tab li{
list-style:none;
float:left;
text-align:center;
padding:0;
}
#tab a{
display:block;
text-decoration:none;
width:94px;
line-height:24px;
}
#cont{
clear:both;
border:1px solid blue;
border-top:0;
width:562px!important;
width:564px;
height:190px;
overflow-y:hidden;
}
.common{
margin:5px;
}
.common li{
list-style:none;
padding-left:14px!important;
padding-left:0;
padding-top:4px;
}
.common li a{
text-decoration:none;
}
.common li a:hover{
color:red;
}
.on{
background:url(images/tabs3.gif) no-repeat left bottom;
}
.off{
background:url(images/tabs2.gif) no-repeat left bottom;
}
</style>
<script>
function $(ID){
return document.getElementById(ID)
}
function showTab(ID){
for(var i=1;i<7;i++){
if(ID==i){
$(&#39;tab&#39;+i).blur();
$("tab"+i).className="on";
$("cont"+i).style.display="block";
}else{
$("tab"+i).className="off";
$("cont"+i).style.display="none";
}
}
return false;
}
</script>
</head>
<body>
<p id="main">
<p id="tab">
<ul>
<li><a href="javascript:void(0)" id="tab1" class="on" onclick="showTab(&#39;1&#39;)">C#源代码</a></li>
<li><a href="javascript:void(0)" id="tab2" class="off" onclick="showTab(&#39;2&#39;)">VB源代码</a></li>
<li><a href="javascript:void(0)" id="tab3" class="off" onclick="showTab(&#39;3&#39;)">VC源代码</a></li>
<li><a href="javascript:void(0)" id="tab4" class="off" onclick="showTab(&#39;4&#39;)">JQUERY脚本</a></li>
<li><a href="javascript:void(0)" id="tab5" class="off" onclick="showTab(&#39;5&#39;)">Delphi代码</a></li>
<li><a href="javascript:void(0)" id="tab6" class="off" onclick="showTab(&#39;6&#39;)">JAVA源代码</a></li>
</ul>
</p>
<p id="cont" >
<p id="cont1" class="common" style="display:block;">
<li><a href="#" target="_blank">30多个C#基础学习实例</a></li>
</p>
<p style="display:none;" id="cont2" class="common">
<li><a href="#" target="_blank">VB仿Photoshop曲线调整图像亮度源程序</a></li>
</p>
<p style="display:none;" id="cont3" class="common">
<li><a href="#" target="_blank">VC仿RealonePlayer播放器的窗体界面</a></li>
</p>
<p style="display:none;" id="cont4" class="common">
<li><a href="#" target="_blank">Farbtastic jQuery圆形网页取色插件</a></li>
</p>
<p style="display:none;" id="cont5" class="common">
<li><a href="#" target="_blank">Delphi基础学习实例代码</a></li>
</p>
<p style="display:none;" id="cont6" class="common">
<li><a href="#" target="_blank">Java图书管理程序代码</a></li>
</p>
</p>
</p>
</body>
</html>

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to native js simulating Taobao shopping cart

JS realizes silverware with 3D stereoscopic effect Code for gray vertical folding menu

The above is the detailed content of JS implementation method to change sliding door to tab. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn