动画扩展/收缩表

时间:2016-07-07 03:39:27

标签: javascript jquery angularjs html-table expand

现在,下面的代码显示了一个表格,其中包含点击时展开/收缩的行数。我想让每一行在点击时向下滑动内容。我该怎么做?

function MyCtrl($scope) {
  $scope.environment_service_packages = 
    [
      {name: 'Click to expand', info: {text: 'some extra info', show: false}},
      {name: 'obj2', info: {text: 'some extra info for obj2', show: false}},
    ];
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app>
  <table ng-controller="MyCtrl" class="table table-hover table-striped">
    <tr class="info">
      <td>...</td>
    </tr>
    <tbody ng-repeat="x in environment_service_packages">
      <tr ng-click="x.info.show = !x.info.show">
        <td> {{ x.name }}
      </tr>
      <tr ng-show="x.info.show">
        <td>
          {{ x.info.text }}
        </td>
      </tr>
    </tbody>
  </table>
</body>

1 个答案:

答案 0 :(得分:1)

试试这个。我刚添加了一个淡入淡出。尝试一些其他效果,看看它有效。
礼貌这个令人敬畏的图书馆(animate.css)[https://daneden.github.io/animate.css/]

function MyCtrl($scope) {
  $scope.environment_service_packages = [{
    name: 'Click to expand',
    info: {
      text: 'some extra info',
      show: false
    }
  }, {
    name: 'obj2',
    info: {
      text: 'some extra info for obj2',
      show: false
    }
  }, ];
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet" />

<body ng-app>
  <table ng-controller="MyCtrl" class="table table-hover table-striped">
    <tr class="info">
      <td>...</td>
    </tr>
    <tbody ng-repeat="x in environment_service_packages">
      <tr ng-click="x.info.show = !x.info.show">
        <td>{{ x.name }}
      </tr>
      <tr ng-show="x.info.show" class="animated fadeIn">
        <td>
          {{ x.info.text }}
        </td>
      </tr>
    </tbody>
  </table>
</body>