动画元素角度不消失
Animated element angular not disappearing
这基本上是我的问题:http://jsfiddle.net/mhff6u7y/3/
我有一个数组的项目重复和过滤,有时我动画其中一个项目。问题是,当过滤器发生更改,并且已设置动画的项目不应再显示时,该项目将一直保留到完成动画为止。所以,是的,为什么当我更改过滤器时,动画元素会保留而不会消失?
代码(与jsfiddle相同):
HTML(需要导入:angular.js、angular-animate.js、animate.min.css):
<div ng-controller="MyCtrl">
<label>
<input type="number" min="1" max="3" ng-model="choice.number" />
</label>
<br>
selected number: {{ choice.number }}
<div class="loader">
<div class="item"
ng-repeat="item in list | filter: { number:choice.number}"
ng-class="{'animated':item == animatedItem}"
ng-click="animatedItem = item;">
{{item.text}}
</div>
</div>
</div>
css:
@-webkit-keyframes myanimation{
0% { opacity: 1.0; }
50% { opacity: 0.5; }
100% { opacity: 1.0; }
}
.loader {
position: absolute;
top: 100px;
left: 100px;
padding: 5px;
border-radius: 2px;
background: #eee;
}
.item {
margin: 5px;
border-radius: 2px;
background-color: #808080;
}
.animated {
animation-name: myanimation;
animation-duration: 1s;
animation-timing-function: linear;
animation-iteration-count: 50;
-webkit-animation-name:myanimation;
-webkit-animation-duration: 1s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: 50;
}
JavaScript:
var myApp = angular.module('myApp',['ngAnimate']);
myApp.controller('MyCtrl', function($scope) {
$scope.isThinking = true;
$scope.animatedItem = {};
$scope.list = [{'number': 1, 'text': 'item1'},
{'number': 1, 'text': 'item11'},
{'number': 1, 'text': 'item111'},
{'number': 2, 'text': 'item2'},
{'number': 2, 'text': 'item22'},
{'number': 2, 'text': 'item222'},
{'number': 3, 'text': 'item3'},
{'number': 3, 'text': 'item33'},
{'number': 3, 'text': 'item333'}];
});
提前感谢
我在这里得到了答案:https://github.com/angular/angular.js/issues/13436
答案:
"这不是bug,这是ngAnimate的工作方式。.animated上的动画由ngRepeat拾取,并被解释为离开动画,这就是为什么元素会一直保留到动画结束。这是因为ngAnimate允许同时拥有多个动画。因此,为了不混淆动画引擎,您应该从样式中排除特定的"结构"动画,请参见此处:http://plnkr.co/edit/onBcM37KxV2X3S5SgtuX?p=preview'
所以基本上在css中添加":not(.ng leave)":
.animated:not(.ng-leave) {
animation-name: myanimation;
animation-duration: 1s;
animation-timing-function: linear;
animation-iteration-count: 50;
-webkit-animation-name:myanimation;
-webkit-animation-duration: 1s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: 50;
}
相关文章:
- 当实现javascript倒计时时,其他html元素将消失
- 复选框元素在未选中时从serialize()中消失
- Selenium-webdriver (Java Script) 等待元素消失
- 空的数组绑定元素在页面加载时消失
- 元素在使用 jQuery 对相对包装宽度进行动画处理时消失
- 按钮会因Chrome中同级元素上的动画而消失
- 如何防止动态添加的元素在页面重新加载后消失
- Javascript在秒消失时显示DIV元素,并在此之后隐藏栏的选项
- 使用 JavaScript 使表单元素消失
- HTML5 画布元素消失
- 语义 UI 模态导致我的元素在关闭后从 DOM 中消失
- 为什么当我对其父元素进行动画处理时,我的 UL 消失了
- 当元素消失时,不会触发鼠标输出
- 使元素在页面底部消失
- 如何使固定的元素在非固定元素后面消失
- Javascript - 如果选择了某个选项,则使元素消失
- 元素在淡入 () 后立即再次消失
- 消失元素上的OnClick事件
- 正在使用jQuery UI显示带有模式消息的消失元素
- fullPage.js中的消失元素