Calculate scale factor of elements in FLIP animations

- divide the getBoundingClientRect dimensions by clientHeight or clientWidth
  - this gives us the element's scaled values as scaleX and scaleY
- divide the "dx" and "dy" by the "scaleX" and "scaleY"

This aims to fix #3555 by using the node's un-scaled width/height to
calculate the amount it has been scaled. Then dividing the distance by
this scale factor removes the janky start position which was shown in
the test case.

resolves #3555
pull/3627/head
simeydotme 5 years ago
parent 5dda05213e
commit fbf4cbf22c

@ -19,9 +19,11 @@ interface FlipParams {
export function flip(node: Element, animation: { from: DOMRect; to: DOMRect }, params: FlipParams): AnimationConfig {
const style = getComputedStyle(node);
const transform = style.transform === 'none' ? '' : style.transform;
const scaleX = animation.from.width / node.clientWidth;
const scaleY = animation.from.height / node.clientHeight;
const dx = animation.from.left - animation.to.left;
const dy = animation.from.top - animation.to.top;
const dx = (animation.from.left - animation.to.left) / scaleX;
const dy = (animation.from.top - animation.to.top) / scaleY;
const d = Math.sqrt(dx * dx + dy * dy);

Loading…
Cancel
Save