Skip to content

Add transition to open/close carousel #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions src/lib/components/gallery-carousel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type GalleryImage = (ImageRecord | ImageThumbnails) & {
export let images: Array<GalleryImage>
export let initialIndex: number
export let onClose: () => void
export let send
export let receive

let carousel: HTMLElement

Expand Down Expand Up @@ -60,6 +62,8 @@ function handleEscape(event: KeyboardEvent) {
class="flex snap-center items-center justify-center p-2 md:p-4 xl:p-8"
data-index={index}
on:click|self|stopPropagation={onClose}
in:receive={{ key: index }}
out:send={{ key: index }}
>
<div class="group relative">
<ImageLens {image} lazyLoad={false} />
Expand Down
4 changes: 4 additions & 0 deletions src/lib/components/lens-gallery.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import MasonryGrid from './masonry-grid.svelte'
export let images
export let isHidden
export let onOpen
export let send
export let receive
</script>

<MasonryGrid items={images} gapClass="gap-4 md:gap-8 xl:gap-16">
Expand All @@ -17,6 +19,8 @@ export let onOpen
class:opacity-30={isHidden}
data-index={index}
on:click={onOpen(index)}
in:receive={{ key: index }}
out:send={{ key: index }}
>
<ImageLens
image={item.thumbnails}
Expand Down
34 changes: 26 additions & 8 deletions src/routes/photos/screen-shots/[slug]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script>
import { crossfade, scale } from 'svelte/transition'

import GalleryCarousel from '$lib/components/gallery-carousel.svelte'
import LensGallery from '$lib/components/lens-gallery.svelte'
import PageIntro from '$lib/components/page-intro.svelte'
Expand All @@ -9,12 +11,22 @@ export let data
$: ({ title, subtitle, description, images, content } = data.json)
$: fullTitle = subtitle ? [title, subtitle].join(' ') : title

let isCarouselOpen = false
let isCarouselOpen = null
let initialIndex = 0

const [send, receive] = crossfade({
duration: 200,
fallback: scale,
})

async function handleOpenCarousel(index) {
isCarouselOpen = true
initialIndex = index
const image = new Image()

image.addEventListener('load', () => {
isCarouselOpen = true
initialIndex = index
})
image.src = `${images[index].path.replace(/^static/, '')}`
}

function handleCloseCarousel() {
Expand Down Expand Up @@ -44,13 +56,19 @@ function handleCloseCarousel() {
{images}
isHidden={isCarouselOpen}
onOpen={handleOpenCarousel}
{send}
{receive}
/>
{#if isCarouselOpen}
<GalleryCarousel
{images}
{initialIndex}
onClose={handleCloseCarousel}
/>
{#await isCarouselOpen then}
<GalleryCarousel
{images}
{initialIndex}
onClose={handleCloseCarousel}
{send}
{receive}
/>
{/await}
{/if}
<div class="prose prose-invert md:prose-xl">
{@html content}
Expand Down