gpt4 book ai didi

javascript - 如何在 Angular 1.2 中使用 ng-animate?

转载 作者:行者123 更新时间:2023-12-03 03:45:20 24 4
gpt4 key购买 nike

基础

Angular 1.1.5 - http://plnkr.co/edit/eoKt8o4MJw9sWdYdeG3s?p=preview - 作品

上调

Angular 1.2.6 - http://plnkr.co/edit/WopgAtFNVm1mKf5Li99h?p=preview - 失败

<小时/>

我想我确实遵循了文档中的说明 - http://docs.angularjs.org/api/ngAnimate

• First include angular-animate.js in your HTML

• Then load the module in your application by adding it as a dependent module

在我的时区已经很晚了,我可能错过了一些明显的事情。我的猜测是 - 1.1.5 和 1.2.6 之间的 CSS 文件不兼容?实在说不出来...

无论如何,这里是代码形式 upped plunker,我添加了一些注释来强调我遵循了文档中的说明:

<!doctype html>
<html ng-app="app">
<head>
<meta charset="utf-8">
<title>Top Animation</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css">
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="http://code.angularjs.org/1.2.6/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-animate.js"></script>
<!-- ^^^ load animate -->
</head>

<script>
var app = angular.module('app', ['ngAnimate']); // <-- dependent module

app.controller('Ctrl', function($scope) {
$scope.names = ['Igor Minar', 'Brad Green', 'Dave Geddes', 'Naomi Black', 'Greg Weber', 'Dean Sofer', 'Wes Alvaro', 'John Scott', 'Daniel Nadasi'];
});

</script>

<body ng-controller="Ctrl">
<div class="well" style="margin-top: 30px; width: 200px; overflow: hidden;">
<form class="form-search">
<div class="input-append">
<input type="text" ng-model="search" class="search-query" style="width: 80px">
<button type="submit" class="btn">Search</button>
</div>
<ul class="nav nav-pills nav-stacked">
<li ng-animate="'animate'" ng-repeat="name in names | filter:search">
<a href="#"> {{name}} </a>
</li>
</ul>
</form>
</div>
</body>
</html>

非常感谢您的帮助!

最佳答案

这是你的骗子的工作版本... http://plnkr.co/edit/05irGvYwD4y9ZRb1ZHSw?p=preview

在 Angular 1.2+ 中,您不再需要声明 ng-animate 指令。动画可以单独使用 css 添加。因此,对于您的示例,您可以删除 ng-animate 指令并为元素提供一个 css 类,因此更改...

<li ng-animate="'animate'" ng-repeat="name in names | filter:search">

to...

<li class="animate" ng-repeat="name in names | filter:search">

然后将你的 css 更新为...

.animate.ng-enter, 
.animate.ng-leave
{
...

.animate.ng-leave.animate.ng-leave-active,
.animate.ng-enter {
...

.animate.ng-enter.ng-enter-active,
.animate.ng-leave {
...

Angular 将简单地将 ng-enter、ng-hide、ng-leave 等类添加到元素中,并在动画生命周期中适本地删除它们,这将触发 css 动画。 docs 中列出了哪些指令支持哪些动画类。在“使用情况”下。在此示例中,我们正在对 ng-repeat 进行动画处理,因此 ng-enter、ng-leave 和 ng-move 类将在适当的时间添加到我们的元素中,并且我们可以使用 css 将动画附加到它们。

关于javascript - 如何在 Angular 1.2 中使用 ng-animate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21591860/

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