1

我有一个指令触发一个动画,当从 / 位置移开时,该动画将 div 移高 200px。只要 / 位置是我们的起点,这很好用,但是当从另一条路线开始时,仍然到达 addClass,但没有执行。

angular.module('app').
directive('topPosition', ['$location', '$animate', '$rootScope', function (location, $animate,     $rootScope) {
return {
    restrict: 'A',
    link: function (scope, element, attrs) {
        scope.location = location;
        scope.$watch('location.path()', function (newPath) {
            if (newPath !== '/') {
                $animate.addClass(element, 'higher');
            } else {
                $animate.removeClass(element, 'higher');
            }
        });
    }
}
}])

动画代码

angular.module('app')
.animation(".higher", function () {
    return {
        addClass: function (element, className, done) {
            TweenMax.to(element,1, { y: '-200' });
        },
        removeClass: function (element, className , done) {
            TweenMax.to(element, 1, {y: 0});
        }
    }
});

我在这里做错了什么?

4

0 回答 0