jquery仿Google Play风格的tab折页选项卡切换代码



104 412 138



特效描述: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

加群请备注:从官网了解到