From 60fdf02112ff403d4b2c117dc03139b4f10931db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Mon, 6 Apr 2020 12:14:48 +0200 Subject: [PATCH] Photo: Tweak reveal animations and fix horizontal scroll - Photo number doesn't jumps anymore (now reveals based on photo not the number) - Properly reveal title locations lines - Optimize code --- src/animations/Photo.js | 73 ++++++++++++++++++-------------- src/molecules/Photo.svelte | 22 +++++----- src/style/molecules/_photo.scss | 9 +++- src/style/organisms/_photos.scss | 13 +++--- 4 files changed, 67 insertions(+), 50 deletions(-) diff --git a/src/animations/Photo.js b/src/animations/Photo.js index 8b83b66..b850902 100644 --- a/src/animations/Photo.js +++ b/src/animations/Photo.js @@ -2,30 +2,40 @@ import anime from 'animejs' import ScrollOut from 'scroll-out' import imagesLoaded from 'imagesloaded' import { throttle, parallaxAnime } from 'utils/functions' +import { animDuration } from 'utils/store' /* ** Transition In */ export const animateIn = scope => { - // Title (reveal on scroll) - const titleReveal = ScrollOut({ + const tlLocation = anime.timeline({ + easing: 'easeOutQuart', + duration: 1000, + autoplay: false + }) + // Title + tlLocation.add({ + targets: scope.querySelectorAll('.photo__location .line span'), + translateY: ['100%', 0], + delay: anime.stagger(120) + }, 200) + // Description + tlLocation.add({ + targets: scope.querySelectorAll('.photo__location p'), + opacity: [0, 1], + duration: animDuration + }, 400) + + // Reveal on scroll + const photoReveal = ScrollOut({ once: true, - targets: scope.querySelector('h2'), - onShown (el) { - // Title reveal - anime({ - targets: el.querySelectorAll('span'), - translateY: ['100%', 0], - easing: 'easeOutQuart', - duration: 1000, - delay: anime.stagger(120) - }) - } + targets: scope, + onShown: () => tlLocation.restart() }) - // Photo (reveal on scroll) + // Image (reveal on scroll) const photoImage = scope.querySelector('.photo__image') const photoAnim = anime.timeline({ easing: 'easeOutQuart', @@ -46,29 +56,30 @@ export const animateIn = scope => { const photoReveal = ScrollOut({ once: true, targets: photoImage, - onShown: el => photoAnim.restart() + onShown: () => photoAnim.restart() }) }) // Number parallax on scroll - const nbParallaxMedia = window.matchMedia('(min-width: 768px)') - const nbParallax = matchMedia => { + const media768 = window.matchMedia('(min-width: 768px)') + const number = scope.querySelector('.photo__number') + const numberPallax = anime({ + targets: number.querySelector('span'), + translateY: (window.innerWidth <= 768) ? ['0%', '20%'] : ['-20%', '20%'], + duration: 2000, + easing: 'linear', + autoplay: false + }) + const numberPallaxScroll = matchMedia => { if (matchMedia.matches) { const scroll = ScrollOut({ - targets: scope.querySelector('.photo__number span'), - onShown (el) { - const translate = anime({ - targets: el, - translateY: (window.innerWidth <= 768) ? ['0%', '20%'] : ['-15%', '15%'], - duration: 2000, - easing: 'linear', - autoplay: false - }) - window.addEventListener('scroll', throttle(() => parallaxAnime(el, translate), 50)) - requestAnimationFrame(() => parallaxAnime(el, translate)) + targets: scope, + onShown: (el) => { + window.addEventListener('scroll', throttle(() => parallaxAnime(el, numberPallax), 50)) + requestAnimationFrame(() => parallaxAnime(el, numberPallax)) }, - onHidden () { + onHidden: () => { if (parallaxAnime) window.removeEventListener('scroll', parallaxAnime) } }) @@ -76,6 +87,6 @@ export const animateIn = scope => { } // Listen on screen size to run the function - nbParallaxMedia.addListener(nbParallax) - nbParallax(nbParallaxMedia) + media768.addListener(numberPallax) + numberPallaxScroll(media768) } diff --git a/src/molecules/Photo.svelte b/src/molecules/Photo.svelte index 33a0ba8..9a0d352 100644 --- a/src/molecules/Photo.svelte +++ b/src/molecules/Photo.svelte @@ -37,8 +37,11 @@

- {name.split(', ')[0]}, - {name.split(', ')[1]} + {#each name.split(', ') as line, i} + + {name.split(', ')[i]}, + + {/each}

{location.region}, {location.country.name}

@@ -48,20 +51,15 @@
- + - {#if layout === 'list'} - {imgAlt}