教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 Jquery 经典选项卡的实现代码一例

Jquery 经典选项卡的实现代码一例

发布时间:2015-10-15   编辑:jiaochengji.com
为大家介绍一个用js代码实现的经典选项卡,有需要的朋友,可以参考下。

需要引入外部jquery文件与Css文件,大家自行完成吧。

代码如下:

<!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> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>选项卡-www.jbxue.com</title> <script type="text/javascript" src="/common/jquery132min.js"></script> <link type="text/css" rel="stylesheet" href="/common/common.css" /> <style type="text/css"> /* 选项卡 */ .tab{width:500px;border:#ccc 1px solid;margin:100px;} .tab dl dt{ border-bottom:#ccc 1px solid;height:25px;background:#f1f1f1; margin-bottom:-1px;} .tab dl dt a{float:left;display:block;cursor:pointer;width:60px;height:25px;line-height:25px; text-align:center;background:#f1f1f1;color:#000;} .tab dl dt a.tabActive{background:#fff;color:#333;font-weight:bold;border-bottom:1px solid #fff; position:relative;border-right:1px solid #ccc;border-left:1px solid #ccc;} .tab dl dd{padding:10px;height:200px; clear:both;} </style> </head> <body> <script type="text/javascript"> // 选项卡 $(function(){ $(".tab dl dt>a:first").addClass("tabActive"); $(".tab dl dd ul").not(":first").hide(); $(".tab dl dt>a").unbind("click").bind("click", function(){ $(this).siblings("a").removeClass("tabActive").end().addClass("tabActive"); var index = $(".tab dl dt>a").index( $(this) ); $(".tab dl dd ul").eq(index).siblings(".tab dl dd ul").hide().end().fadeIn("slow"); }); }); </script> <script type="text/javascript"> // 自动轮换选项卡 $(document).ready(function(){ $('.tab dl dt a:first').addClass('tabActive'); $('.tab dl dd ul:first').css('display','block'); autoroll(); hookThumb(); }); var i=-1; //第i+1个tab开始 var offset = 2500; //轮换时间 var timer = null; function autoroll(){ n = $('.tab dl dt a').length-1; i++; if(i > n){ i = 0; } slide(i); timer = window.setTimeout(autoroll, offset); } function slide(i){ $('.tab dl dt a').eq(i).addClass('tabActive').siblings().removeClass('tabActive'); $('.tab dl dd ul').eq(i).fadeIn("slow").siblings('.tab dl dd ul').hide(); } function hookThumb(){ $('.tab dl dt a').hover( function () { if (timer) { clearTimeout(timer); i = $(this).prevAll().length; slide(i); } }, function () { timer = window.setTimeout(autoroll, offset); this.blur(); return false; } ); } </script> <!-- 选项卡 --> <div class="tab"> <dl> <dt><a>tab1</a><a>tab2</a><a>tab3</a><a>tab4</a></dt> <dd> <ul>脚本学堂</ul> <ul>www.jbxue.com</ul> <ul>脚本学堂_www.jbxue.com</ul> <ul>http://www.jbxue.com</ul> </dd> </dl> </div> </body> </html>

您可能感兴趣的文章:
Jquery 经典选项卡的实现代码一例
纯 CSS 选项卡的实现例子
JQuery Tab选项卡效果代码改进版
jquery自动切换tabs选项卡的实现代码
Jquery tab选项卡的实现代码
jQuery学习笔记(3)--用jquery(插件)实现多选项卡功能
基于jquery的修改当前TAB显示标题的代码
jquery ui tabs获取选中的实现代码
jQuery 网页选项卡的示例代码
jquery代码-在弹出窗口中打开链接和在选项卡中打开链接

[关闭]
~ ~