Use flip from svelte/animate

pull/2589/head
Jaspreet Singh 7 years ago
parent 0d420b4782
commit f51da6e1e1

@ -1,7 +1,7 @@
<script>
import { quintOut } from 'svelte/easing';
import { flip } from 'svelte/animate';
import crossfade from './crossfade.js'; // TODO put this in svelte/transition!
import { flip } from './flip.js';
const { send, receive } = crossfade({
fallback(node, params) {
@ -12,9 +12,9 @@
duration: 600,
easing: quintOut,
css: t => `
transform: ${transform} scale(${t});
opacity: ${t}
`,
transform: ${transform} scale(${t});
opacity: ${t}
`,
};
},
});

@ -1,24 +0,0 @@
import { cubicOut } from 'svelte/easing';
export function flip(node, animation, params) {
const style = getComputedStyle(node);
const transform = style.transform === 'none' ? '' : style.transform;
const dx = animation.from.left - animation.to.left;
const dy = animation.from.top - animation.to.top;
const d = Math.sqrt(dx * dx + dy * dy);
const {
delay = 0,
duration = d => Math.sqrt(d) * 120,
easing = cubicOut
} = params;
return {
delay,
duration: typeof duration === 'function' ? duration(d) : duration,
easing,
css: (t, u) => `transform: ${transform} translate(${u * dx}px, ${u * dy}px);`
};
}

@ -1,7 +1,7 @@
<script>
import { quintOut } from 'svelte/easing';
import { flip } from 'svelte/animate';
import crossfade from './crossfade.js'; // TODO put this in svelte/transition!
import { flip } from './flip.js';
const { send, receive } = crossfade({
fallback(node, params) {
@ -12,9 +12,9 @@
duration: 600,
easing: quintOut,
css: t => `
transform: ${transform} scale(${t});
opacity: ${t}
`,
transform: ${transform} scale(${t});
opacity: ${t}
`,
};
},
});

@ -1,24 +0,0 @@
import { cubicOut } from 'svelte/easing';
export function flip(node, animation, params) {
const style = getComputedStyle(node);
const transform = style.transform === 'none' ? '' : style.transform;
const dx = animation.from.left - animation.to.left;
const dy = animation.from.top - animation.to.top;
const d = Math.sqrt(dx * dx + dy * dy);
const {
delay = 0,
duration = d => Math.sqrt(d) * 120,
easing = cubicOut
} = params;
return {
delay,
duration: typeof duration === 'function' ? duration(d) : duration,
easing,
css: (t, u) => `transform: ${transform} translate(${u * dx}px, ${u * dy}px);`
};
}
Loading…
Cancel
Save