1- import { getRect , css , isScrolledPast , matrix , isRectEqual , indexOfObject } from './utils.js' ;
1+ import { getRect , css , matrix , isRectEqual , indexOfObject } from './utils.js' ;
22import Sortable from './Sortable.js' ;
33
44export default function AnimationStateManager ( ) {
@@ -17,7 +17,7 @@ export default function AnimationStateManager() {
1717 target : child ,
1818 rect : getRect ( child )
1919 } ) ;
20- let fromRect = getRect ( child ) ;
20+ let fromRect = { ... animationStates [ animationStates . length - 1 ] . rect } ;
2121
2222 // If animating: compensate for current animation
2323 if ( child . thisAnimationDuration ) {
@@ -70,29 +70,6 @@ export default function AnimationStateManager() {
7070
7171 target . toRect = toRect ;
7272
73- // If element is scrolled out of view: Do not animate
74- if (
75- (
76- isScrolledPast ( target , toRect , 'bottom' , 'top' ) ||
77- isScrolledPast ( target , toRect , 'top' , 'bottom' ) ||
78- isScrolledPast ( target , toRect , 'right' , 'left' ) ||
79- isScrolledPast ( target , toRect , 'left' , 'right' )
80- ) &&
81- (
82- isScrolledPast ( target , animatingRect , 'bottom' , 'top' ) ||
83- isScrolledPast ( target , animatingRect , 'top' , 'bottom' ) ||
84- isScrolledPast ( target , animatingRect , 'right' , 'left' ) ||
85- isScrolledPast ( target , animatingRect , 'left' , 'right' )
86- ) &&
87- (
88- isScrolledPast ( target , fromRect , 'bottom' , 'top' ) ||
89- isScrolledPast ( target , fromRect , 'top' , 'bottom' ) ||
90- isScrolledPast ( target , fromRect , 'right' , 'left' ) ||
91- isScrolledPast ( target , fromRect , 'left' , 'right' )
92- )
93- ) return ;
94-
95-
9673 if ( target . thisAnimationDuration ) {
9774 // Could also check if animatingRect is between fromRect and toRect
9875 if (
@@ -120,6 +97,7 @@ export default function AnimationStateManager() {
12097 this . animate (
12198 target ,
12299 animatingRect ,
100+ toRect ,
123101 time
124102 ) ;
125103 }
@@ -151,16 +129,15 @@ export default function AnimationStateManager() {
151129 animationStates = [ ] ;
152130 } ,
153131
154- animate ( target , prev , duration ) {
132+ animate ( target , currentRect , toRect , duration ) {
155133 if ( duration ) {
156134 css ( target , 'transition' , '' ) ;
157135 css ( target , 'transform' , '' ) ;
158- let currentRect = getRect ( target ) ,
159- elMatrix = matrix ( this . el ) ,
136+ let elMatrix = matrix ( this . el ) ,
160137 scaleX = elMatrix && elMatrix . a ,
161138 scaleY = elMatrix && elMatrix . d ,
162- translateX = ( prev . left - currentRect . left ) / ( scaleX || 1 ) ,
163- translateY = ( prev . top - currentRect . top ) / ( scaleY || 1 ) ;
139+ translateX = ( currentRect . left - toRect . left ) / ( scaleX || 1 ) ,
140+ translateY = ( currentRect . top - toRect . top ) / ( scaleY || 1 ) ;
164141
165142 target . animatingX = ! ! translateX ;
166143 target . animatingY = ! ! translateY ;
0 commit comments