From a4f4b557050c585e2286dfda30c41032d2c4bb78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Tue, 21 Apr 2020 18:12:32 +0200 Subject: [PATCH] Carousel: Fix reveal --- src/animations/Carousel.js | 46 ++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/animations/Carousel.js b/src/animations/Carousel.js index 928e73f..2d75d25 100644 --- a/src/animations/Carousel.js +++ b/src/animations/Carousel.js @@ -52,27 +52,29 @@ export const animateIn = scope => { // Reveal on scroll let visible = false - const carouselReveal = ScrollOut({ - once: true, - targets: scope, - onChange: (el, ctx) => { - requestAnimationFrame(() => { - if (ctx.visible === 0) { - visible = true - } - }) - }, - onShown: (el, ctx) => { - requestAnimationFrame(() => { - // If revealed on scroll, no delay - if (visible) { - tl.restart() - } - // If revealed on load, add a delay - else { - setTimeout(() => tl.restart(), animDelay * 2) - } - }) - } + requestAnimationFrame(() => { + const carouselReveal = ScrollOut({ + once: true, + targets: scope, + onChange: (el, ctx) => { + requestAnimationFrame(() => { + if (ctx.visible === 0) { + visible = true + } + }) + }, + onShown: (el, ctx) => { + requestAnimationFrame(() => { + // If revealed on scroll, no delay + if (visible) { + tl.restart() + } + // If revealed on load, add a delay + else { + setTimeout(() => tl.restart(), animDelay * 2) + } + }) + } + }) }) } \ No newline at end of file