【发布时间】:2015-04-27 21:55:12
【问题描述】:
我正在尝试创建一个指令来为元素的高度设置动画。 问题是我正在根据数据计算元素的高度,所以我无法提前创建一个我将添加动画的类。
我每次都需要添加不同值的 height 属性
这是我目前的指令:
.directive('graph', ['$document', '$animate', function ($document, $animate) {
return {
restrict: 'A',
link: function (scope, element, attributes) {
var newClass = {height: attributes['height']}
$animate.addClass(element, newClass);
}
};
}]);
但这行不通。应该怎么解决?
如果我改用会怎样:
element.css({height: newClass});
这会起作用,但是如果我能做到这么简单,为什么我还有 $animate 服务呢?
【问题讨论】: