Use reveal function to animate Locations items

This commit is contained in:
2021-11-21 13:51:11 +01:00
parent 7e29caf2c2
commit c618141f51

View File

@@ -1,10 +1,10 @@
<script lang="ts"> <script lang="ts">
import { getContext, onMount } from 'svelte' import { getContext } 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' import { reveal, fly } from '$animations/index'
// 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'
@@ -12,8 +12,6 @@
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
@@ -38,41 +36,6 @@
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 () => {
observer.disconnect()
}
})
</script> </script>
<div class="browse" id="locations"> <div class="browse" id="locations">
@@ -91,7 +54,18 @@
{/each} {/each}
</ul> </ul>
<ul class="browse__locations" bind:this={listEl}> <ul class="browse__locations"
use:reveal={{
animation: fly,
options: {
children: 'li',
stagger: 100,
duration: 1200,
from: '20%',
},
threshold: 0.3,
}}
>
{#each filteredLocations as location (location)} {#each filteredLocations as location (location)}
<li <li
animate:flip={{ duration: 1000, easing: quartOut }} animate:flip={{ duration: 1000, easing: quartOut }}