Add reveal animation on Locations list

This commit is contained in:
2021-11-17 21:51:26 +01:00
parent bf54dccd57
commit df1e6f7311

View File

@@ -1,17 +1,19 @@
<script lang="ts"> <script lang="ts">
import { getContext } from 'svelte' import { getContext, onMount } from 'svelte'
import { flip } from 'svelte/animate' import { flip } from 'svelte/animate'
import { quartOut } from 'svelte/easing' import { quartOut } from 'svelte/easing'
import { send, receive } from '$animations/crossfade' import { send, receive } from '$animations/crossfade'
import { throttle } from '$utils/functions' import { throttle } from '$utils/functions'
import anime from 'animejs'
// Components // Components
import Button from '$components/atoms/Button.svelte' import Button from '$components/atoms/Button.svelte'
import Location from '$components/molecules/Location.svelte' import Location from '$components/molecules/Location.svelte'
export let locations: any export let locations: any
const { continents, settings: { explore_list }} = getContext('global') const { continents, settings: { explore_list }} = getContext('global')
let listEl: HTMLElement
let observer: IntersectionObserver
// Continents filtering logic // Continents filtering logic
let currentContinent: string = undefined let currentContinent: string = undefined
@@ -36,6 +38,40 @@
currentContinent = undefined currentContinent = undefined
} }
}, 700) }, 700)
onMount(() => {
const items = listEl.querySelectorAll('li')
anime.set(items, { opacity: 0 })
// Init IO
observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
anime({
targets: items,
translateY: ['20%', 0],
opacity: [0, 1],
duration: 1200,
delay: anime.stagger(100),
easing: 'easeOutQuart',
})
// Run once only
observer.unobserve(listEl)
}
})
}, {
threshold: 0.3,
rootMargin: '0px 0px 0px'
})
observer.observe(listEl)
// Destroy
return () => {
}
})
</script> </script>
<div class="browse" id="locations"> <div class="browse" id="locations">
@@ -54,7 +90,7 @@
{/each} {/each}
</ul> </ul>
<ul class="browse__locations" role="list"> <ul class="browse__locations" bind:this={listEl}>
{#each filteredLocations as location (location)} {#each filteredLocations as location (location)}
<li <li
animate:flip={{ duration: 1000, easing: quartOut }} animate:flip={{ duration: 1000, easing: quartOut }}