Merge pull request #2407 from sveltejs/better-transitions

better transitions
pull/2418/head
Rich Harris 6 years ago committed by GitHub
commit 49679cc586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,19 +18,22 @@ export function fly(node, {
duration = 400, duration = 400,
easing = cubicOut, easing = cubicOut,
x = 0, x = 0,
y = 0 y = 0,
opacity = 0
}) { }) {
const style = getComputedStyle(node); const style = getComputedStyle(node);
const opacity = +style.opacity; const target_opacity = +style.opacity;
const transform = style.transform === 'none' ? '' : style.transform; const transform = style.transform === 'none' ? '' : style.transform;
const od = target_opacity * (1 - opacity);
return { return {
delay, delay,
duration, duration,
easing, easing,
css: t => ` css: (t, u) => `
transform: ${transform} translate(${(1 - t) * x}px, ${(1 - t) * y}px); transform: ${transform} translate(${(1 - t) * x}px, ${(1 - t) * y}px);
opacity: ${t * opacity}` opacity: ${target_opacity - (od * u)}`
}; };
} }
@ -73,13 +76,12 @@ export function scale(node, {
start = 0, start = 0,
opacity = 0 opacity = 0
}) { }) {
const sd = 1 - start; const style = getComputedStyle(node);
const od = 1 - opacity; const target_opacity = +style.opacity;
const transform = style.transform === 'none' ? '' : style.transform;
const transform = ( const sd = 1 - start;
node.style.transform || const od = target_opacity * (1 - opacity);
getComputedStyle(node).transform
).replace('none', '');
return { return {
delay, delay,
@ -87,18 +89,29 @@ export function scale(node, {
easing, easing,
css: (t, u) => ` css: (t, u) => `
transform: ${transform} scale(${1 - (sd * u)}); transform: ${transform} scale(${1 - (sd * u)});
opacity: ${1 - (od * u)} opacity: ${target_opacity - (od * u)}
` `
}; };
} }
export function draw(node, { export function draw(node, {
delay = 0, delay = 0,
duration = 800, speed,
duration,
easing = cubicInOut easing = cubicInOut
}) { }) {
const len = node.getTotalLength(); const len = node.getTotalLength();
if (duration === undefined) {
if (speed === undefined) {
duration = 800;
} else {
duration = len / speed;
}
} else if (typeof duration === 'function') {
duration = duration(len);
}
return { return {
delay, delay,
duration, duration,

Loading…
Cancel
Save