add and remove image for smoothness

This commit is contained in:
saiminh 2023-08-23 18:24:11 +02:00
parent 64b0de7013
commit de7172f686
4 changed files with 42 additions and 17 deletions

View file

@ -7,13 +7,10 @@
<Header /> <Header />
{#key data.pathname} {#key data.pathname}
<div
<div class="content"
class="content" >
<slot />
> </div>
<slot /> {/key}
</div>
{/key}

View file

@ -1,9 +1,10 @@
<script lang="ts"> <script lang="ts">
import WorkCanvas from '$lib/components/WorkCanvas.svelte'; import WorkCanvas from '$lib/components/WorkCanvas.svelte';
import { onMount } from 'svelte'; import { onDestroy, onMount } from 'svelte';
import { workClickHandler, initWorkPage } from './workUtils.js'; import { workClickHandler, initWorkPage } from './workUtils.js';
import { workbulge } from '$lib/utils/stores.js'; import { workbulge } from '$lib/utils/stores.js';
import { CldImage } from 'svelte-cloudinary'; import { CldImage } from 'svelte-cloudinary';
import { browser } from '$app/environment';
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
export let data; export let data;
@ -28,13 +29,20 @@
<div class="works"> <div class="works">
{#each data.posts as work, i} {#each data.posts as work, i}
<a href="{work.path}" class="work" on:click={ (e) => workClickHandler(e) }> <a
data-sveltekit-preload-data
href="{work.path}"
class="work"
on:click={ (e) => workClickHandler(e) }
>
<CldImage <CldImage
src={work.meta.header_bg_image} src={work.meta.header_bg_image}
sizes="(min-width: 768px) 20vw, 50vw" sizes="(min-width: 768px) 20vw, 50vw"
alt={work.meta.title} alt={work.meta.title}
width="2100" width="2100"
height="1400" height="1400"
objectFit="fill"
placeholder="blur"
loading= {i < 10 ? "eager" : "lazy"} loading= {i < 10 ? "eager" : "lazy"}
/> />
<h2>{work.meta.title}</h2> <h2>{work.meta.title}</h2>

View file

@ -122,6 +122,7 @@
sizes="100vw" sizes="100vw"
width={2100} width={2100}
height={1400} height={1400}
placeholder="blur"
loading="eager" loading="eager"
objectFit="fill" objectFit="fill"
/> />
@ -143,8 +144,10 @@
<style lang="scss"> <style lang="scss">
article { article {
width: 100vw; width: 100vw;
min-height: 100svh;
overflow: hidden; overflow: hidden;
padding-bottom: 60px; padding-bottom: 60px;
background-color: var(--color-bg);
} }
.subnav { .subnav {
position: fixed; position: fixed;
@ -162,10 +165,6 @@
height: auto; height: auto;
aspect-ratio: var(--aspect-ratio-heroes); aspect-ratio: var(--aspect-ratio-heroes);
clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%); clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%);
@media screen and (min-width: 768px) {
position: fixed;
}
} }
:global(.heromask img) { :global(.heromask img) {
z-index: 0; z-index: 0;

View file

@ -59,7 +59,12 @@ export function workClickHandler(e:Event){
const clone = targetImg.cloneNode(true) as HTMLElement; const clone = targetImg.cloneNode(true) as HTMLElement;
targetImg.parentElement?.insertBefore(clone, targetImg); targetImg.parentElement?.insertBefore(clone, targetImg);
targetImg.style.position = 'fixed'; targetImg.style.position = 'fixed';
const coverclone = targetImg.cloneNode(true) as HTMLElement;
coverclone.style.zIndex = '-1';
coverclone.style.visibility = 'visible';
coverclone.style.opacity = '0';
document.body.appendChild(coverclone);
gsap.to('.work:not(.active) img', { gsap.to('.work:not(.active) img', {
duration: .3, duration: .3,
@ -70,6 +75,16 @@ export function workClickHandler(e:Event){
gsap.set(targetImg, { gsap.set(targetImg, {
zIndex: 100, zIndex: 100,
}) })
gsap.to(coverclone, {
duration: .3,
top: 0,
left: 0,
opacity: 1,
width: window.innerWidth,
height: window.innerWidth / targetImgAspectRatio,
ease: 'circ.inOut',
delay: 0.3
})
gsap.to(targetImg, { gsap.to(targetImg, {
duration: .3, duration: .3,
top: 0, top: 0,
@ -78,6 +93,12 @@ export function workClickHandler(e:Event){
height: window.innerWidth / targetImgAspectRatio, height: window.innerWidth / targetImgAspectRatio,
ease: 'circ.inOut', ease: 'circ.inOut',
delay: 0.3, delay: 0.3,
onComplete: () => {
setTimeout(() => {
coverclone.remove();
}, 300);
}
}) })
gsap.to(bulge, { gsap.to(bulge, {
duration: .3, duration: .3,