【发布时间】:2014-11-29 13:51:22
【问题描述】:
我对@987654321@ 的collapse 指令有一个简单的问题。我有一个<select> 菜单。当有人更改菜单时,内容也会发生变化。但是,我想在应用这些更改之前添加一个动画。具体来说,我希望该部分在显示新内容之前折叠和取消折叠。我可以折叠它,但我想知道如何检测折叠何时完成,以便我可以展开它。
我可以使用我目前使用的$timeout方法,但是感觉“hackish”和“不正确”,因为如果折叠动画的时间发生变化,那么我必须再次更改时间。
相关代码:
.directive("myBufferAnimation", function($timeout) {
var ignoreFirst = true;
return function(scope, element, attrs) {
scope.$watch("selectBuffer", function(newValue) {
if (ignoreFirst) {
ignoreFirst = false;
return;
}
scope.toCollapse = true;
// Detect end of animation here?
// Bogus solution, as this just waits for one second rather than listening for the end of animation
$timeout(function() {
scope.selected = newValue;
scope.toCollapse = false;
}, 1000);
});
}
});
这个jsfiddle 说明了问题。
【问题讨论】:
标签: javascript html angularjs angular-ui-bootstrap