gpt4 book ai didi

javascript - 动画扩展/收缩表格

转载 作者:行者123 更新时间:2023-11-27 22:48:39 27 4
gpt4 key购买 nike

现在,下面的代码显示了一个表格,其中的行在单击时会展开/收缩。我希望每一行的内容在单击时向下和向上滑动。我该怎么做?

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>

最佳答案

试试这个。我刚刚添加了一个淡入。尝试一些其他效果,看看是否有效。
礼貌这个很棒的库 (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>

关于javascript - 动画扩展/收缩表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38237198/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com