jquery仿Google Play風格的tab折頁選項卡切換代碼



107 427 143



特效描述:tab折頁選項卡 選項卡切換,

代碼結構

1. 引入JS

<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>

2. HTML代碼

<div style="width:720px;margin:40px auto 0 auto;">
  <ul id="tabs">
      <li><a href="#" name="#tab1">One</a></li>
      <li><a href="#" name="#tab2">Two</a></li>
      <li><a href="#" name="#tab3">Three</a></li>
      <li><a href="#" name="#tab4">Four</a></li>    
  </ul>
  <div id="content">
      <div id="tab1">
          <h2>Lorem ipsum sit amet</h2>
          <p>Praesent risus nisi, iaculis nec condimentum vel, rhoncus vel dolor. Aenean nisi lectus, varius nec tempus id, dapibus non quam.</p>
          <p>Suspendisse ac libero mauris. Cras lacinia porttitor urna, vitae molestie libero posuere et. Mauris turpis tortor, mollis non vulputate sit amet, rhoncus vitae purus.</p>
          <h3>Pellentesque habitant</h3>
          <p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae.</p>    
      </div>
      <div id="tab2">
          <h2>Vivamus fringilla suscipit justo</h2>
          <p>Aenean dui nulla, egestas sit amet auctor vitae, facilisis id odio. Donec dictum gravida feugiat.</p>
          <p>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras pretium elit et erat condimentum et volutpat lorem vehicula</p>
          <p>Morbi tincidunt pharetra orci commodo molestie. Praesent ut leo nec dolor tempor eleifend.</p>    
      </div>
      <div id="tab3">
          <h2>Phasellus non nibh</h2>
          <p>Non erat laoreet ullamcorper. Pellentesque magna metus, feugiat eu elementum sit amet, cursus sed diam. Curabitur posuere porttitor lorem, eu malesuada tortor faucibus sed.</p>
          <h3>Duis pulvinar nibh vel urna</h3>
          <p>Donec purus leo, porttitor eu molestie quis, porttitor sit amet ipsum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec accumsan ornare elit id imperdiet. </p>
          <p>Suspendisse ac libero mauris. Cras lacinia porttitor urna, vitae molestie libero posuere et. </p>
      </div>
      <div id="tab4">
          <h2>Cum sociis natoque penatibus</h2>
          <p>Magnis dis parturient montes, nascetur ridiculus mus. Nullam ac massa quis nisi porta mollis venenatis sit amet urna. Ut in mauris velit, sed bibendum turpis.</p>
          <p>Nam ornare vulputate risus, id volutpat elit porttitor non. In consequat nisi vel lectus dapibus sodales. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent bibendum sagittis libero.</p>
          <h3>Imperdiet sem interdum nec</h3>
          <p>Mauris rhoncus tincidunt libero quis fringilla.</p>    
      </div>
  </div>
</div>  
<script type="text/javascript">
function resetTabs(){
	$("#content > div").hide(); //隱藏所有內容
	$("#tabs a").attr("id",""); //重置“id”   
}
var myUrl = window.location.href; //取得超鏈地址
var myUrlTab = myUrl.substring(myUrl.indexOf("#")); 
var myUrlTabName = myUrlTab.substring(0,4);
(function(){
	$("#content > div").hide(); // 最初隱藏所有內容
	$("#tabs li:first a").attr("id","current"); // 激活第一個選項卡
	$("#content > div:first").fadeIn(); // 顯示第一個選項卡的內容
	$("#tabs a").on("click",function(e) {
		e.preventDefault();
		if ($(this).attr("id") == "current"){ //檢測當前選項卡
			return       
		}else{             
			resetTabs();
			$(this).attr("id","current"); // 激活這
			$($(this).attr('name')).fadeIn(); // 顯示當前選項卡的內容
		}
	});
	for (i = 1; i <= $("#tabs li").length; i++) {
		if(myUrlTab == myUrlTabName + i){
			resetTabs();
			$("a[name='"+myUrlTab+"']").attr("id","current"); // 激活url選項卡
			$(myUrlTab).fadeIn(); // 顯示url選項卡內容      
		}
	}
})()
</script>



用戶評論
大牛,別默默的看了,快登錄幫我點評一下吧!:)      登錄 | 注冊


熱門標簽: 滾動切換 滾動條切換 滑動選項卡 滑動切換 選項卡切換 選項卡 切換 tab切換 頁面切換 選項卡插件 切換插件 滑動手風琴 選項卡自動切換
?
×
×

注冊

官方QQ群

掃描上面二維碼加微信群

官方QQ群

jQuery/js討論群
群號:642649996
Css3+Html5討論群
群號:322131262

加群請備注:從官網了解到

老夫子电子