jquery實現的滑動門程式碼例項

admin發表於2017-02-23

滑動門其實就是選項卡效果,只是叫法不懂而已,下面是一個典型的滑動門程式碼例項。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
.main{
  height:160px;
  width:290px;
  border:1px solid #444444;
  font-size:12px;
  color:#444444;
  margin:20px;
}
.main_top{
  height:30px;
  width:290px;
  line-height:30px;
  text-align:left;
  background-color:#999999;
  border-bottom:1px solid #444444;
}
.main_top ul{
  padding:0px;
  margin:0px;
  list-style-type:none;
  position:absolute;
}
.main_top ul li.h_qian{
  float:left;
  width:80px;
  text-align:center;
  background-color:#999999;
  height:30px;
}
.main_top ul li.h_hou{
  float:left;
  width:80px;
  text-align:center;
  background-color:#ffffff;
  cursor:pointer;
  margin-top:1px;
  height:30px;
  font-weight:bold;
}
.main_content{
  margin:10px;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript">
function tabchange(obj,p,c,q,h) {
  $(obj).parent().find("li").attr("class", ""+q+"");
  $(obj).parents("."+p+"").find("."+c+"").hide();
  $(obj).attr("class", ""+h+"");
  var j=$(obj).index();
  $(obj).parents("."+p+"").find("."+c+":eq(" + j + ")").show();
}
</script>
</head>
<body>
<div class="main">
 <div class="main_top">
  <ul>
   <li class="h_hou" onmouseover="tabchange(this,'main','main_content','h_qian','h_hou')">第一模組</li>
   <li class="h_qian" onmouseover="tabchange(this,'main','main_content','h_qian','h_hou')">第二模組</li>
   <li class="h_qian" onmouseover="tabchange(this,'main','main_content','h_qian','h_hou')">第三模組</li>
  </ul>
 </div>
 <div class="main_content">螞蟻部落一</div>
 <div class="main_content" style="display:none;">螞蟻部落二</div>
 <div class="main_content" style="display:none;">螞蟻部落三</div>
</div>
</body>
</html>

相關文章