栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

AngularJS实现tab选项卡的方法详解

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

AngularJS实现tab选项卡的方法详解

本文实例讲述了AngularJS实现tab选项卡的方法。分享给大家供大家参考,具体如下:

一、代码实现



  
    
    
    
      *{
 list-style: none;
 margin: 0;
 padding: 0;
      }
      .TabNav{
 height: 131px;
 width: 450px;
 position: relative;
 margin-left: auto;
 margin-right: auto;
 margin-top: 100px;
      }
      .TabNav ul li{
 float: left;
 background: -webkit-gradient(linear,left top,left bottom, from(#fefefe), to(#ededed));
 border: 1px solid #ccc;
 padding: 5px 0;
 width: 100px;
 text-align: center;
 margin-left: -1px;
 position: relative;
 cursor: pointer;
      }
      .TabCon{
 position: absolute;
 left: -1px;
 top: 30px;
 border: 1px solid #ccc;
 border-top: none;
 width: 403px;
 height: 100px;
      }
      .TabNav ul li.active{
 background: #FFFFFF;
 border-bottom: none;
      }
    
    
  
  
    
      
  • 许嵩
  • 周杰伦
  • 林俊杰
  • 陈奕迅
断桥残雪、千百度、幻听、想象之中 红尘客栈、牛仔很忙、给我一首歌的时间、听妈妈的话 被风吹过的夏天、江南、一千年以后 十年、K歌之王、浮夸

二、效果预览

三、实现原理

选项卡的内容是显示还是隐藏是由activeTab的值决定的,而这个值是通过选项卡上面的ng-click指令设置的,当对应选项卡的内容显示的时候,给点击的按钮添加样式,这样做虽然也能实现选项卡的内容,但是这样做的的弊端是,选项卡的内容是固定的,不好去改变,所以接下来我们将上面的代码改成下面这种形式

四、改版



  
    
    
    
      *{
 list-style: none;
 margin: 0;
 padding: 0;
      }
      .TabNav{
 height: 131px;
 position: relative;
 margin-left: 100px;
 margin-top: 100px;
      }
      .TabNav ul li{
 float: left;
 background: -webkit-gradient(linear,left top,left bottom, from(#fefefe), to(#ededed));
 border: 1px solid #ccc;
 padding: 5px 0;
 width: 100px;
 text-align: center;
 margin-left: -1px;
 position: relative;
 cursor: pointer;
      }
      .TabCon{
 position: absolute;
 left: -1px;
 top: 30px;
 border: 1px solid #ccc;
 border-top: none;
 width: 403px;
 height: 100px;
      }
      .TabNav ul li.active{
 background: #FFFFFF;
 border-bottom: none;
      }
    
    
  
  
    
      
  • {{item.list}}
{{item.con}}

说明:vm这个数组里面是我们自己定义的一些假数据(这个数据实际上是可以从后台获取的),然后我们通过ng-repeat指令循环遍历出vm里面的数据,插入到页面中,$index是每个内容对象的索引值

更多关于AngularJS相关内容感兴趣的读者可查看本站专题:《AngularJS指令操作技巧总结》、《AngularJS入门与进阶教程》及《AngularJS MVC架构总结》

希望本文所述对大家AngularJS程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/86544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号