zoukankan      html  css  js  c++  java
  • 导航折叠菜单

    大概效果:

    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/
  • 相关阅读:
    各种颜色对应的16进制
    django之旅 1.hello world
    FlexPaper文档在线浏览
    windwos下django 安装配置
    Josn 序列化
    WCF服务
    easy_install遇上Unable to find vcvarsall.bat
    Android开发环境搭建(jdk+eclip+android sdk)
    安卓系统架构图(转)
    windows8和windows server2012不联网安装.net 3.5(包括2.0和3.0)
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/14236605.html
Copyright © 2011-2022 走看看