From a1801490d56b24d2bdc72f3fc2cd28b773ff926f Mon Sep 17 00:00:00 2001 From: martinlaxenaire Date: Tue, 10 Oct 2023 15:05:22 +0200 Subject: [PATCH] - FIXED PAGE TRANSITIONS!!! see https://github.com/sveltejs/kit/issues/7405#issuecomment-1301004664 - cleanup + webgl planes correctly removed, removed hacks --- src/app.css | 2 +- src/lib/components/ProjectListHover.svelte | 4 +- src/lib/components/ProjectListItem.svelte | 18 +-------- src/lib/components/ScrollPlane.svelte | 43 ++++++++++++---------- src/lib/storyblok/Header.svelte | 4 +- src/routes/+layout.svelte | 2 +- src/routes/PageTransition.svelte | 4 +- src/routes/work/+page.svelte | 24 ++---------- src/routes/work/MenuItem.svelte | 4 +- 9 files changed, 40 insertions(+), 65 deletions(-) diff --git a/src/app.css b/src/app.css index a1578c27..a614f8f8 100644 --- a/src/app.css +++ b/src/app.css @@ -58,4 +58,4 @@ margin-top: -8px; padding: 8px 0; } -} \ No newline at end of file +} diff --git a/src/lib/components/ProjectListHover.svelte b/src/lib/components/ProjectListHover.svelte index f8dc31b9..fa7a729d 100644 --- a/src/lib/components/ProjectListHover.svelte +++ b/src/lib/components/ProjectListHover.svelte @@ -29,12 +29,12 @@ style="--color: #dbd5bf;" > {title} diff --git a/src/lib/components/ProjectListItem.svelte b/src/lib/components/ProjectListItem.svelte index c796c4ed..c809fb27 100644 --- a/src/lib/components/ProjectListItem.svelte +++ b/src/lib/components/ProjectListItem.svelte @@ -11,7 +11,6 @@ export let content: any; export let isMainItem: boolean; export let layout: 'left' | 'right' = 'left'; - export let useCurtainsPlanes: boolean = true; function onEnter() { project_list_hover.set(name); @@ -73,7 +72,7 @@ window.addEventListener('smoothScrollUpdate', onScroll); return () => { - resizeObserver.unobserve(document.body) + resizeObserver.disconnect() // this function is called when the component is destroyed window.removeEventListener('smoothScrollUpdate', onScroll); }; @@ -97,20 +96,7 @@ on:mouseenter={onEnter} on:mouseleave={onLeave} > - {#if useCurtainsPlanes} - - {:else} -
- {name} -
- {/if} +
diff --git a/src/lib/components/ScrollPlane.svelte b/src/lib/components/ScrollPlane.svelte index fd5f70b0..599d7454 100644 --- a/src/lib/components/ScrollPlane.svelte +++ b/src/lib/components/ScrollPlane.svelte @@ -100,18 +100,30 @@ opacity: { name: 'uOpacity', type: '1f', - value: 1 + value: 0 } } }; const createPlane = () => { if (curtains && canCreatePlane && planeEl) { - console.log('create plane', name, planeEl) params.renderOrder = curtains.planes.length; plane = new Plane(curtains, planeEl, params); + const inTransition = { + opacity: plane.uniforms.opacity.value, + } + + gsap.to(inTransition, { + opacity: 1, + duration: 0.5, + ease: 'power2.inOut', + onUpdate: () => { + plane.uniforms.opacity.value = inTransition.opacity + } + }) + plane.onRender(() => { const scroll = ScrollSmoother.get(); const velocity = clamp(scroll.getVelocity() * 0.01, -60, 60); @@ -133,34 +145,27 @@ } }); - // isPageHidden.subscribe((value: boolean) => { - // isHidden = value; - // if (value && isTransition && !canCreatePlane) { - // // coming from a page transition - // // wait a couple ticks for old planes to be removed first - // canCreatePlane = true; - // createPlane(); - // setTimeout(() => { - // createPlane(); - // }, 32); - // } - // }); - + let resizeObserver: ResizeObserver | null; useCurtains( (curtainsInstance) => { curtains = curtainsInstance; createPlane(); + + resizeObserver = new ResizeObserver(() => { + if(plane) plane.resize() + }) + + resizeObserver.observe(document.body) }, (curtainsInstance) => { - // TODO not triggered after using work page filters!! - // https://github.com/sveltejs/svelte/issues/5268 ? if (plane) { - console.log('plane removed', plane.index, name); + //console.log('plane removed', plane.index, name); plane.remove(); plane = null; - curtainsInstance.resize(); } + + resizeObserver?.disconnect() } ); diff --git a/src/lib/storyblok/Header.svelte b/src/lib/storyblok/Header.svelte index 8960424a..34235eef 100644 --- a/src/lib/storyblok/Header.svelte +++ b/src/lib/storyblok/Header.svelte @@ -94,8 +94,8 @@
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index b13bc8c0..ad2c9f2f 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -117,7 +117,7 @@
- + {#if data.settings} {/if} diff --git a/src/routes/PageTransition.svelte b/src/routes/PageTransition.svelte index cea53986..fb661090 100644 --- a/src/routes/PageTransition.svelte +++ b/src/routes/PageTransition.svelte @@ -22,12 +22,12 @@ {#key pathname}
diff --git a/src/routes/work/+page.svelte b/src/routes/work/+page.svelte index 1197e3db..95d676bd 100644 --- a/src/routes/work/+page.svelte +++ b/src/routes/work/+page.svelte @@ -24,7 +24,8 @@ let containerEl: HTMLElement; - $: filter = $page.url.searchParams.get('filter'); + //$: filter = $page.url.searchParams.get('filter'); + $: filter = $page.url.hash.slice(1); /** * @param {any} projects @@ -82,15 +83,6 @@ } }; - // force removing all projects planes when navigating away - // works even if we have used the filters - $: useCurtainsPlanes = true as boolean; - $: if ($navigating) { - if (curtains && $navigating?.from?.route.id === '/work' && filter !== '') { - useCurtainsPlanes = false; - } - } - onMount(() => { if (data.story) { useStoryblokBridge(data.story.id, (newStory) => (data.story = newStory)); @@ -118,13 +110,6 @@ } ); - // update planes sizes and positions - /** - async function hashchange() { - await tick(); - if (curtains) curtains.resize(); - } - */
@@ -134,7 +119,7 @@ {#each categories as category, i} @@ -142,7 +127,7 @@ @@ -161,7 +146,6 @@ {content} isMainItem={index === 0} layout={index % 2 === 0 ? 'left' : 'right'} - {useCurtainsPlanes} class={getProjectGridItemClass(index)} />
diff --git a/src/routes/work/MenuItem.svelte b/src/routes/work/MenuItem.svelte index d721a603..4a8b34ec 100644 --- a/src/routes/work/MenuItem.svelte +++ b/src/routes/work/MenuItem.svelte @@ -12,8 +12,8 @@