首页 > 开发 > AJAX > 正文

AngularJS tab栏实现和mvc小案例实例详解

2024-09-01 08:27:12
字体:
来源:转载
供稿:网友

tab栏:

代码:

<!DOCTYPE html> <html lang="en"> <head>   <meta charset="UTF-8">   <title>Tab 标签</title>   <style>     body {       margin: 0;       padding: 0;       background-color: #F7F7F7;     }     .tabs {       width: 400px;       margin: 30px auto;       background-color: #FFF;       border: 1px solid #C0DCC0;       box-sizing: border-box;     }     img {       width: 400px;     }     .tabs nav {       height: 40px;       text-align: center;       line-height: 40px;       overflow: hidden;       background-color: #C0DCC0;       display: flex;     }     nav a {       display: block;       width: 100px;       border-right: 1px solid #FFF;       color: #000;       text-decoration: none;     }     nav a:last-child {       border-right: 0 none;     }     nav a.active {       background-color: #9BAF9B;     }     .cont {       overflow: hidden;       /*display: none;*/     }     .cont ol {       line-height: 30px;     }     p {       text-align: center;       height: 30px;       line-height: 30px;     }     li {       list-style: none;       height: 30px;       line-height: 30px;     }   </style>   <!--[if lte IE 6]>   <![endif]--> </head> <body ng-app="Tabs">   <div class="tabs" ng-controller="TabsController">     <nav>     <!-- 指令之间没有分号 -->       <a href="javascript:;" ng-class="{active: type == 'local'}" ng-mouseover="switch('local')">白山茶</a>       <a href="javascript:;" ng-class="{active: type == 'global'}" ng-mouseover="switch('global')">作曲</a>       <a href="javascript:;" ng-class="{active: type == 'sports'}" ng-mouseover="switch('sports')">背景</a>       <a href="javascript:;" ng-class="{active: type == 'funny'}" ng-mouseover="switch('funny')">歌词</a>     </nav>     <div ng-switch on="type">       <section class="cont" ng-switch-when="local">         <p>2017.5.24</p>       </section>       <section class="cont" ng-switch-when="global">         <p>作曲:陈雪凝</p>         <p>作词:陈雪凝</p>         <p>编曲:海艺音乐</p>       </section>       <section class="cont" ng-switch-when="sports">           <img src="bsc.png">       </section>       <section class="cont" ng-switch-when="funny">         <ul>           <li>你认真的说你喜欢白山茶</li>           <li>怡然自得的收起别的红玫瑰</li>           <li>你温柔的说你眷恋我</li>           <li>然后迫不及待的爱别人</li>           <li>然后迫不及待的爱别人</li>           <li>然后迫不及待的爱别人</li>           <li>然后迫不及待的爱别人</li>         </ol>       </section>     </div>   </div>   <script src="../../js/angular.min.js"></script>   <script>     angular.module('Tabs',[]).controller('TabsController',['$scope',function($scope){        $scope.type = 'local';        $scope.switch = function(type){         $scope.type = type;        }     }]);   </script> </body> </html>             
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表