From 761bfa7486defa97b6953187baf529d2affb3185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Wed, 11 Mar 2020 18:33:35 +0100 Subject: [PATCH] Transition: Don't animate height So use a background div to squeeze and move other elements as well --- src/animations/Transition.js | 45 +++++++++++++++++++++--------------- src/style/_animations.scss | 28 +++++++++++++++++++--- src/utils/Transition.svelte | 23 ++++++++++-------- 3 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/animations/Transition.js b/src/animations/Transition.js index 7ced515..a1cd93f 100644 --- a/src/animations/Transition.js +++ b/src/animations/Transition.js @@ -8,21 +8,22 @@ import { animDuration, animDurationLong } from '../utils/store' export const animateIn = scope => { // Panel itself const transition = anime({ - targets: scope, - height: ['100%', '100%'], - scale: [1.1, 1], + targets: scope.querySelector('.transition__background'), + scaleY: [1, 1], opacity: [0, 1], duration: 400, - delay: 0, - easing: 'easeInOutQuart' + easing: 'easeInOutQuart', + begin () { + // Show the panel + scope.classList.remove('hidden') + } }) // Globe icon const globe = anime({ targets: scope.querySelector('svg'), opacity: [0, 1], - translateY: [32, 0], + translateY: ['16px', 0], duration: 400, - delay: 0, easing: 'easeInOutQuart' }) @@ -33,31 +34,39 @@ export const animateIn = scope => { ** Transition Out */ export const animateOut = (scope, callback) => { - // Panel itself - const transition = anime({ - targets: scope, - height: ['100%', 0], + // Background + const background = anime({ + targets: scope.querySelector('.transition__background'), + scaleY: [1, 0], duration: animDurationLong, delay: 800, easing: 'easeInOutQuart', - complete: callback + complete () { + // Hide the panel + scope.classList.add('hidden') + + // Run callback + callback() + } }) // Title const title = anime({ targets: scope.querySelector('.title-location'), - opacity: 0, - duration: 600, - delay: 1400, + opacity: [1, 0], + translateY: [0, '-50vh'], + duration: animDuration, + delay: 1000, easing: 'easeInOutQuart' }) // Globe icon const globe = anime({ targets: scope.querySelector('svg'), - opacity: 0, - duration: 600, - delay: 1400, + opacity: [1, 0], + translateY: [0, '-50vh'], + duration: animDuration, + delay: 1000, easing: 'easeInOutQuart' }) } diff --git a/src/style/_animations.scss b/src/style/_animations.scss index 9cc4139..c52d314 100644 --- a/src/style/_animations.scss +++ b/src/style/_animations.scss @@ -7,13 +7,35 @@ left: 0; width: 100%; height: 100%; - z-index: 1000; + z-index: 10000; overflow: hidden; display: flex; align-items: center; justify-content: center; - background-color: $color-primary; - will-change: height, transform, padding-top, padding-bottom; + will-change: transform; + + // Content + &__loader { + position: relative; + z-index: 2; + } + + // Background + &__background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: $color-primary; + transform-origin: 50% 0; + will-change: transform; + } + + // Hidden + &.hidden { + display: none; + } } diff --git a/src/utils/Transition.svelte b/src/utils/Transition.svelte index eca845b..b5c8865 100644 --- a/src/utils/Transition.svelte +++ b/src/utils/Transition.svelte @@ -24,16 +24,18 @@ let firstLoad = true // 1. Watch page change - page.subscribe(() => { - // Run the loader animation (only after first load) - if (!firstLoad && process.browser) { - animateIn(scope) + page.subscribe(page => { + if (!page.params.photo) { + // Run the loader animation (only after first load) + if (!firstLoad && process.browser) { + animateIn(scope) + } + + // TODO: Figure out how to delay the page rendering a little bit before the end of the transition panel ending + + // Set pageReady to false (?) + pageReady.set(false) } - - // TODO: Figure out how to delay the page rendering a little bit before the end of the transition panel ending - - // Set pageReady to false (?) - pageReady.set(false) }) // 2. Watch when loaded changes @@ -60,7 +62,7 @@