【问题标题】:Angularjs - How to collapse and expand the accordion slowly with animationAngularjs - 如何用动画慢慢折叠和展开手风琴
【发布时间】:2019-05-31 17:14:10
【问题描述】:

我正在使用 angularjs 并有一个带有展开和折叠的简单手风琴,一切正常,但是当我展开 div 时它应该慢慢展开,同样,当我再次折叠时它应该慢慢折叠。这里我使用 isopen在angularjs中展开。任何人都可以帮助我,下面是我的代码,https://plnkr.co/edit/nCdGzZYPSTYsMPYf8K9o?p=preview

HTML

<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.1/angular.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.1/angular-sanitize.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.js'></script>
<script  src="js/index.js"></script>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css'>
 <body ng-app="app">
    <h1>Dynamic accordion: nested lists with html markup</h1>   
  <div ng-controller="AccordionDemoCtrl">
    <div>
      <div  ng-repeat="group in groups track by $index">
        <div class="parents"  ng-click="open($index)"><i ng-class="{'glyphicon-minus': group.isOpen, 'glyphicon-plus': !group.isOpen}"></i> {{ group.title }}        
        </div>
        <div class="childs" ng-show="group.isOpen">ddddd</div>

      </div>
    </div>
  </div>
  </body>

index.js

var app=angular.module('app', ['ui.bootstrap','ngSanitize','angular.filter']);
app.controller('AccordionDemoCtrl', function ($scope) {
  $scope.oneAtATime = true;

  $scope.open = function (index) {
    $scope.groups[index].isOpen = !$scope.groups[index].isOpen;
    $scope.closeOthers(index);
  }

  $scope.closeOthers = function (index) {
    for(var i = 0; i  < $scope.groups.length; i++) {
       if (i !== index)
        $scope.groups[i].isOpen = false;
    }
  }

  $scope.groups = [
    {
      title: 'title 1',

      list: ['<i>item1a</i> blah blah',
        'item2a',
        'item3a']
    },
    {
      title: 'title 2',

      list: ['item1b',
        '<b>item2b </b> blah ',
        'item3b'] 
    },
    {
      title: 'title 3',

    },
    {
      title: 'title 4',

    },
    {
      title: 'title 5',

    }
  ];
$scope.groups[0].isOpen = true;
});

【问题讨论】:

    标签: html angularjs twitter-bootstrap


    【解决方案1】:

    你可以使用 css max-height 并添加过渡来使折叠和展开缓慢

    .childs {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.5s ease-out;
    }
    
    .childs.showChild {
        max-height: 1000px;
    }
    <ul class="childs" ng-class="{'showChild': group.isOpen}">
        <li ng-repeat="item in group.list">
            <span ng-bind-html="item"></span>
        </li>
    </ul>
    查看演示 https://plnkr.co/edit/Gm7oe8l3ZBXyWTe3Okm4?p=preview

    【讨论】:

    • 感谢您的回答,但它没有像引导崩溃那样正常发生
    猜你喜欢
    • 1970-01-01
    • 2012-09-23
    • 2021-11-10
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 2018-07-24
    • 2020-01-25
    • 2016-04-25
    相关资源
    最近更新 更多