简体   繁体   English

Angular.js移动动画

[英]Angular.js move animation

I'm having hard time creating a rather simple move animation. 我很难创建一个相当简单的移动动画。

The effect I want to achieve is similar to this http://jsbin.com/vorub/1/edit?output (which I took from some other SO question). 我想要达到的效果类似于这个http://jsbin.com/vorub/1/edit?output (我从其他一些SO问题中得到的)。

Now I managed to do it using .animation() 现在我设法使用.animation()

Basically doing this 基本上这样做

.animation('.move-to-top', [function() {
    return {
        addClass: function(element, className, done) {

            var el = $(element);
            var top = el.position().top;

            el
                .addClass('move-to-top')
                .one('transitionend', function() {

                    setTimeout(function() {
                        el.css({
                            transform: 'scale(1.03) translateY(-' + (top+10) + 'px)'
                        })
                        .one('transitionend', function() {
                            setTimeout(function() {
                                el
                                    .removeClass('move-to-top')
                                    .css({
                                        transform: 'scale(1) translateY(-' + (top) + 'px)'
                                    })
                            }, 50);


                            el.prevAll('.timetracking-item')
                                .css({
                                    transform: 'translateY(' + el.height() + 'px)'
                                });

                        });

                    }, 100);

                });

        }
}
}]);

where move-to-top class does this move-to-top课程的地方

.move-to-top {
    @include vendor(transition, all 400ms ease-in-out);
    @include vendor(transform, scale(1.03) translateY(-10px));

    position: relative;
    z-index: 999;
}

What it does is 它的作用是什么

  1. add class which scales and move item up a bit 添加可以缩放和移动项目的类
  2. move the item to the top using js 使用js将项目移动到顶部
  3. move all previous elements that down to make space using js 移动所有以前的元素,使用js创建空间
  4. remove class that added scaling 删除添加了缩放的类

BUT that's just for the effect and it's done using transforms, which is of course undesirable, so I'd either need to "cleanup" after the transitions are done and remove trasnsforms and actually move the elements in DOM. 但这只是为了效果而且它是使用变换完成的,这当然是不可取的,所以我要么在转换完成后需要“清理”并删除trasnsforms并实际移动DOM中的元素。 Or do it completely differently. 或者完全不同。

Ideal would by orderBy & ng-move combo, but that would require ng-move to have some ng-pre-move , ng-after-move events, which it as far as I know, doesn't. orderByng-move combo是理想的,但是这需要ng-move来进行一些ng-pre-moveng-after-move事件,据我所知,事件并非如此。

Or at least if you could use both addClass: fn() and move: fn() where addClass would fire first(while the element is on the old position), but you can't do this either( addClass doesn't fire when orderBy is applied). 或者至少如果你可以使用addClass: fn()move: fn() ,其中addClass将首先触发(当元素位于旧位置时),但你也不能这样做( addClass不会触发时orderBy被应用)。

The last option I can think about, and like the least, is broadcast some event from my .animation() after all the transitions are done and catch it inside controller, and sort the array then, but I'd need to remove the style attribute from all the items(to remove items) which could and probably will cause flickers . 我能想到的最后一个选项,就像最少的一样,是在完成所有转换后从我的.animation()广播一些事件并将其捕获到控制器中,然后对数组进行排序,但我需要删除该样式来自所有项目(删除项目)的属性,这可能并且可能会导致闪烁

Any other ideas? 还有其他想法吗?

The pre-move is apparently comming in 1.3 https://github.com/angular/angular.js/issues/7609#issuecomment-44615566 前移动显然是在1.3 https://github.com/angular/angular.js/issues/7609#issuecomment-44615566

For now, what I've done was apply ng-if, which forces angular to re-render the whole list. 现在,我所做的是应用ng-if,它强制角度重新渲染整个列表。 Works fine. 工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM