Add reveal animation on Locations list
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
<script lang="ts">
|
||||
import { getContext } from 'svelte'
|
||||
import { getContext, onMount } from 'svelte'
|
||||
import { flip } from 'svelte/animate'
|
||||
import { quartOut } from 'svelte/easing'
|
||||
import { send, receive } from '$animations/crossfade'
|
||||
import { throttle } from '$utils/functions'
|
||||
import anime from 'animejs'
|
||||
// Components
|
||||
import Button from '$components/atoms/Button.svelte'
|
||||
import Location from '$components/molecules/Location.svelte'
|
||||
|
||||
export let locations: any
|
||||
|
||||
|
||||
const { continents, settings: { explore_list }} = getContext('global')
|
||||
let listEl: HTMLElement
|
||||
let observer: IntersectionObserver
|
||||
|
||||
// Continents filtering logic
|
||||
let currentContinent: string = undefined
|
||||
@@ -36,6 +38,40 @@
|
||||
currentContinent = undefined
|
||||
}
|
||||
}, 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>
|
||||
|
||||
<div class="browse" id="locations">
|
||||
@@ -54,7 +90,7 @@
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
<ul class="browse__locations" role="list">
|
||||
<ul class="browse__locations" bind:this={listEl}>
|
||||
{#each filteredLocations as location (location)}
|
||||
<li
|
||||
animate:flip={{ duration: 1000, easing: quartOut }}
|
||||
|
||||
Reference in New Issue
Block a user