【问题标题】:how to use angular $animate with a dynamic computed changing css style如何将角度 $animate 与动态计算变化的 css 样式一起使用
【发布时间】: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 服务呢?

【问题讨论】:

    标签: css angularjs animation


    【解决方案1】:

    试试这个:

    jQuery(element).animate({height: "-=" + value + "px"}, function() {...});
    

    【讨论】:

      猜你喜欢
      • 2017-12-25
      • 2019-12-10
      • 2018-03-17
      • 2023-01-18
      • 1970-01-01
      • 2019-11-16
      • 2018-10-16
      • 2015-01-31
      • 2023-01-30
      相关资源
      最近更新 更多