2
我有一个简单的问题,angularui bootstrap的collapse
指令。我有一个<select>
菜单。当某人改变菜单时,内容改变。但是,我想在应用这些更改之前添加动画。具体而言,我希望在展示新内容之前,该部分可以折叠并展开。我可以将它坍塌,但我想知道如何检测崩溃何时完成,以便我可以将它收缩。AngularJS - 查找崩溃动画结束
我可以使用我当前使用的$timeout
方法,但它感觉“hackish”和“不正确”,因为如果折叠动画的时间发生变化,那么我不得不再次改变时间。
Relavent代码:
.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说明问题。
我注意到你用'的NewClass === “崩溃”'。即使有其他类(因为'newClass'可能会''折叠我的自定义类''或什么的,对吧?)这样工作吗?) – soktinpk 2014-11-22 13:50:57
最新评论更新:我添加了'test-class'到'div '用'my-buffer-animation'指令和上面的代码停止工作,但我认为这可以使用'element.hasClass'或等价物来解决。 – soktinpk 2014-11-22 14:01:16
我尝试过测试你建议的更改,但我在使用的浏览器中出现错误,这可能是由于使用了'classList',并且angularjs获取旧值传递给watch函数的方式。我使用'indexOf'来确定是否存在应该处理多个类名的类名。 'indexOf'可能对于每种情况都不够健壮,但它应该足以满足你正在做的事情。 – 2014-11-22 14:51:23