Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rare-geese-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': minor
---

feat: add crossfade strategies, scale (like before) & size
21 changes: 15 additions & 6 deletions packages/svelte/src/transition/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ export function crossfade({ fallback, ...defaults }) {
const {
delay = 0,
duration = /** @param {number} d */ (d) => Math.sqrt(d) * 30,
easing = cubic_out
easing = cubic_out,
strategy = 'scale'
} = assign(assign({}, defaults), params);
const from = from_node.getBoundingClientRect();
const to = node.getBoundingClientRect();
Expand All @@ -263,11 +264,19 @@ export function crossfade({ fallback, ...defaults }) {
duration: typeof duration === 'function' ? duration(d) : duration,
easing,
css: (t, u) => `
opacity: ${t * opacity};
transform-origin: top left;
transform: ${transform} translate(${u * dx}px,${u * dy}px) scale(${t + (1 - t) * dw}, ${
t + (1 - t) * dh
});
opacity: ${t * opacity};
transform-origin: top left;
transform: ${transform} translate(${u * dx}px, ${u * dy}px) ${
strategy === 'scale' ? `scale(${t + (1 - t) * dw}, ${t + (1 - t) * dh})` : ''
};
${
strategy === 'size'
? `
width: ${to.width + (from.width - to.width) * (1 - t)}px;
height: ${to.height + (from.height - to.height) * (1 - t)}px;
`
: ''
}
`
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/src/transition/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface CrossfadeParams {
delay?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
strategy?: 'scale' | 'size';
}

export * from './index.js';
1 change: 1 addition & 0 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,7 @@ declare module 'svelte/transition' {
delay?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
strategy?: 'scale' | 'size';
}
/**
* Animates a `blur` filter alongside an element's opacity.
Expand Down