• 导航折叠菜单


    大概效果:

    Demo:

    <!DOCTYPE html>
    <html lang="en" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title></title>
        <style media="screen">
          *{
            margin: 0;
            padding: 0;
          }
          ul{
            /*  200px;
            height: 600px;
            background-color: red; */
          }
        </style>
        <script type="text/javascript" src="./lib/jquery-1.12.4.min.js" ></script>
        <script src="https://cdn.staticfile.org/angular.js/1.6.6/angular.min.js"></script>
      </head>
      <body ng-app="myApp">
        <div ng-controller="MyCtrl">
          <ul>
              <li ng-repeat="item in items" ng-click="showChilds($index)">
                  <span>{{item.name}}</span>
                  <ul>
                      <li ng-repeat="subItem in item.subItems" ng-show="item.active" ng-click="clickChild($index)">
                          <span>---{{subItem.name}}</span>
                      </li>
                  </ul>
              </li>
          </ul>
        </div>
        <div class="right">
          
        </div>
    
    <script type="text/javascript">
    var app=angular.module('myApp',[]);
    app.controller('MyCtrl',function($scope){
      $scope.currentIndex = 0;
      $scope.showChilds = function(index){
    
        if ($scope.currentIndex == index) {
          $scope.items[index].active = true;
        }
        else{
          $scope.items[index].active = !$scope.items[index].active;
          collapseAnother(index);
        }
        $scope.currentIndex = index;
    
    
    
      };
    
      var collapseAnother = function(index){
          for(var i=0; i<$scope.items.length; i++){
              if(i!=index){
                  $scope.items[i].active = false;
              }
          }
      };
    
      $scope.clickChild = function(index){
        console.log(index);
      }
    
      $scope.items = [
        {
             name: "Item1",
             subItems: [
                 {name: "SubItem1"},
                 {name: "SubItem2"}
             ]
         },
         {
             name: "Item2",
             subItems: [
                 {name: "SubItem3"},
                 {name: "SubItem4"},
                 {name: "SubItem5"}
             ]
         },
         {
             name: "Item3",
             subItems: [
                 {name: "SubItem6"}
             ]
         }
      ];
    
    });
    </script>
      </body>
    </html>
    

    Angular+Template:

    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    [转] Spring的session管理
    C# 屏幕截图
    C#数字图像处理图像旋转图片加角度
    C#委托
    C# HttpWebRequest 添加Cookie验证
    网站
    前端获取URL中的值
    从下往上画的文字
    测试SSL的网站
    Tomcat-绑定证书的两种方法
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/14236605.html
Copyright © 2020-2023  润新知