Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2431434
  • 博文数量: 328
  • 博客积分: 4302
  • 博客等级: 上校
  • 技术积分: 5486
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-01 11:14
个人简介

悲剧,绝对的悲剧,悲剧中的悲剧。

文章分类

全部博文(328)

文章存档

2017年(6)

2016年(18)

2015年(28)

2014年(73)

2013年(62)

2012年(58)

2011年(55)

2010年(28)

分类: JavaScript

2014-02-11 00:14:32

网上找到两种标签页的实现方法,尝试一下。

一. 利用bootstrap


点击(此处)折叠或打开

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>标签页示例</title>
  6. <link href="" rel="stylesheet">
  7. <script src="" type="text/javascript"></script>
  8. <script src="" type="text/javascript"></script>
  9. </head>

  10. <body style="width:500px; margin:auto;">
  11.   <ul class="nav nav-tabs">
  12.      <li class="active"><a href="#home" data-toggle="tab" >首页</a></li>
  13.      <li class=""><a href="#profile" data-toggle="tab" >介绍</a></li>
  14.   </ul>

  15.   <div class="tab-content">
  16.      <div class="tab-pane active" id="home">
  17.               <p>
  18.         5月6日,北京,一对新人启用直升机接亲。该直升机是欧洲直升机公司系列,机型为AS350B3,该公司北京唯一可承接低空飞行业务的航空公司,此次为首次承接婚礼。据悉,首次空中婚礼总费用为5万元。定价包括飞行时间和申报审批等费用,飞行时间按照1小时3万元计算。
  19.      </p>
  20.      </div>
  21.      <div class="tab-pane" id="profile">
  22.               <p>
  23.         法国代表社会党参选的奥朗德今晨在大选中获得胜利,成为法兰西第五共和国第七位总统,法国也在17年之后迎来首位左翼总统。萨科齐在5年任内因政绩不佳引发不满,选前处于民调落后的劣势。萨科齐虽试图打造“危机总统”形象,但终未能实现逆转。奥朗德现年58岁,至今未婚,与社会党前总统选举候选人罗亚尔同居30多年,育有4子女,多年来坚持骑车上下班。对华关系持强硬立场。
  24.      </p>
  25.      </div>
  26.   </div>
  27. </body>
  28. </html>
详细介绍可以参考这个页面

通过编写代码来实现


点击(此处)折叠或打开

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title> 标签切换 </title>
  6. <style type="text/css">
  7.     * { margin: 0; padding: 0; }
  8.     .box { width: 300px; margin: 0 auto; font: 12px/1.5 'microsoft yahei'; text-align: center; }
  9.     .box .hd { overflow: hidden; }
  10.     .box .hd a { float: left; width: 100px; height: 30px; }
  11.     .box .hd .cur { background-color: #ccc; }
  12.     .box .bd div { width: 300px; height: 100px; line-height: 100px; background-color: #ccc; }

  13.     /* 必须样式 */
  14.     .box .hd .cur { }
  15.     .box .bd div { display: none;}

  16. </style>
  17. </head>
  18. <body>
  19. <!-- 注意:默认选项的栏目有class名,默认切换内容有 display:block; -->
  20. <div class="box" id="oBox">
  21.     <div class="hd">
  22.         <a class="cur" href="">栏目1</a>
  23.         <a href="">栏目2</a>
  24.         <a href="">栏目3</a>
  25.     </div>
  26.     <div class="bd">
  27.         <div style="display: block;">内容1</div>
  28.         <div>内容2</div>
  29.         <div>内容3</div>
  30.     </div>
  31. </div>
  32. <script type="text/javascript">
  33. function TabSwitch (conf){
  34.     this.obj = conf.obj;
  35.     this.cur = conf.cur || 'cur';
  36.     this.hd = conf.hd;
  37.     this.bd = conf.bd;
  38.     this.ev = conf.ev || 'mouseover';
  39.     this.delay = conf.delay || 0;
  40.     this.auto = conf.auto;
  41.     this.index = 0;
  42.     if(this.auto){
  43.         this.delay = conf.delay || 1000;
  44.         this.AutoPaly();
  45.     }else{
  46.         this.Int();
  47.     }
  48. }
  49. TabSwitch.prototype = {
  50.     bindEvent : function(obj, ev, fn){
  51.         var F = function(){
  52.             fn.apply(obj, arguments);
  53.         };
  54.         window.addEventListener ? obj.addEventListener(ev, F, false) : obj.attachEvent("on" + ev, F);
  55.     },
  56.     Switch : function(index){
  57.         for(var n = 0,len = this.hd.length; n < len; n++){
  58.             this.hd[n].className="";
  59.             this.bd[n].style.display = "none";
  60.         }
  61.         this.hd[index].className = this.cur;
  62.         this.bd[index].style.display = "block";
  63.     },
  64.     Int : function(){
  65.         var timer = null,_this = this;
  66.         for(var i = 0, len = this.hd.length; i < len; i++)
  67.         {
  68.             this.hd[i].index = i;
  69.             this.bindEvent(this.hd[i], this.ev, function(){
  70.                 _this.index = this.index;
  71.                 if(_this.delay && !_this.auto){
  72.                     clearTimeout(timer);
  73.                     timer = setTimeout(function(){
  74.                         _this.Switch(_this.index);
  75.                     },_this.delay);
  76.                 }
  77.                 else{
  78.                     _this.Switch(_this.index);
  79.                 }
  80.             });
  81.         }
  82.     },
  83.     Auto : function(){
  84.         if(this.index >= this.hd.length){this.index = 0;}
  85.         this.Switch(this.index);
  86.         this.index ++;
  87.     },
  88.     AutoPaly : function(){
  89.         var timer = null,_this = this;
  90.         clearInterval(timer);
  91.         timer = setInterval(function(){
  92.             _this.Auto();
  93.         },_this.delay);
  94.         this.Events.bindEvent(this.obj, "mouseover", function(){
  95.             clearInterval(timer);
  96.             _this.Int();
  97.         });
  98.         this.Events.bindEvent(this.obj, "mouseout", function(){
  99.             timer = setInterval(function(){
  100.                 _this.Auto();
  101.             },_this.delay);
  102.         });
  103.     }
  104. };
  105. window.onload = function (){
  106.     //by 小鱼,2013/08/20
  107.     var obj = document.getElementById("oBox"),
  108.         aHeadList = obj.getElementsByTagName("div")[0].getElementsByTagName("a"),
  109.         aTabList = obj.getElementsByTagName("div")[1].getElementsByTagName("div");
  110.     /**
  111.      * @obj(ID) 自动播放时必选(用于暂停自动播放)
  112.      * @hd(必选)要切换的头部一组元素
  113.      * @bd(必选)要切换的内容一组元素
  114.      * @cur(可选,string) 头部选中的class,默认cur
  115.      * @ev(可选,string) 触发选项卡的事件,默认mouseover
  116.      * @delay(可选,number)延迟多少毫秒切换,自动播放时默认1000,其他默认0
  117.      * @auto(可选,bool)是否自动播放
  118.      **/
  119.     new TabSwitch({hd:aHeadList, bd:aTabList});
  120. }
  121. </script>
  122. </body>
  123. </html>

阅读(1334) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~