Skip to content

Commit a2be879

Browse files
committed
WIP fix flip
1 parent deb362f commit a2be879

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/svelte/src/animate/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@ export function flip(node, { from, to }, params = {}) {
1919
var dsx = from.width / to.width;
2020
var dsy = from.height / to.height;
2121

22-
var dx = (from.left + dsx * ox - (to.left + ox)) / zoom;
23-
var dy = (from.top + dsy * oy - (to.top + oy)) / zoom;
22+
ox /= node.clientWidth;
23+
oy /= node.clientHeight;
24+
25+
var fromx = from.left + from.width * ox;
26+
var tox = to.left + to.width * ox;
27+
28+
var fromy = from.top + from.height * oy;
29+
var toy = to.top + to.height * oy;
30+
31+
var dx = ((fromx - tox) * (node.clientWidth / to.width)) / zoom;
32+
var dy = ((fromy - toy) * (node.clientHeight / to.height)) / zoom;
2433
var { delay = 0, duration = (d) => Math.sqrt(d) * 120, easing = cubicOut } = params;
2534

2635
return {
@@ -32,7 +41,8 @@ export function flip(node, { from, to }, params = {}) {
3241
var y = u * dy;
3342
var sx = t + u * dsx;
3443
var sy = t + u * dsy;
35-
return `transform: ${transform} scale(${sx}, ${sy}) translate(${x}px, ${y}px);`;
44+
45+
return `transform: ${transform} translate(${x}px, ${y}px) scale(${sx}, ${sy});`;
3646
}
3747
};
3848
}

0 commit comments

Comments
 (0)