Skip to content

Commit b49436e

Browse files
committed
Remove ghost from crossfade during scroll
Fixes: sveltejs#4111
1 parent 5076613 commit b49436e

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/runtime/transition/index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,21 +204,22 @@ interface CrossfadeParams {
204204
easing: EasingFunction;
205205
}
206206

207-
type ClientRectMap = Map<any, { rect: ClientRect }>;
207+
type ElementMap = Map<any, { node: Element }>;
208208

209209
export function crossfade({ fallback, ...defaults }: CrossfadeParams & {
210210
fallback: (node: Element, params: CrossfadeParams, intro: boolean) => TransitionConfig;
211211
}) {
212-
const to_receive: ClientRectMap = new Map();
213-
const to_send: ClientRectMap = new Map();
212+
const to_receive: ElementMap = new Map();
213+
const to_send: ElementMap = new Map();
214214

215-
function crossfade(from: ClientRect, node: Element, params: CrossfadeParams): TransitionConfig {
215+
function crossfade(from_node: Element, node: Element, params: CrossfadeParams): TransitionConfig {
216216
const {
217217
delay = 0,
218218
duration = d => Math.sqrt(d) * 30,
219219
easing = cubicOut
220220
} = assign(assign({}, defaults), params);
221221

222+
const from = from_node.getBoundingClientRect();
222223
const to = node.getBoundingClientRect();
223224
const dx = from.left - to.left;
224225
const dy = from.top - to.top;
@@ -242,18 +243,16 @@ export function crossfade({ fallback, ...defaults }: CrossfadeParams & {
242243
};
243244
}
244245

245-
function transition(items: ClientRectMap, counterparts: ClientRectMap, intro: boolean) {
246+
function transition(items: ElementMap, counterparts: ElementMap, intro: boolean) {
246247
return (node: Element, params: CrossfadeParams & { key: any }) => {
247-
items.set(params.key, {
248-
rect: node.getBoundingClientRect()
249-
});
248+
items.set(params.key, { node });
250249

251250
return () => {
252251
if (counterparts.has(params.key)) {
253-
const { rect } = counterparts.get(params.key);
252+
const from_node = counterparts.get(params.key).node;
254253
counterparts.delete(params.key);
255254

256-
return crossfade(rect, node, params);
255+
return crossfade(from_node, node, params);
257256
}
258257

259258
// if the node is disappearing altogether

0 commit comments

Comments
 (0)