From b6be8a4048d6f663d6d7b29ad2f6e4073b3f9471 Mon Sep 17 00:00:00 2001 From: Maciej Matuszewski Date: Thu, 18 Jan 2018 07:56:38 +0100 Subject: [PATCH] Fix parallax toggle --- src/scripts/parallax.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/scripts/parallax.js b/src/scripts/parallax.js index 2309c48..b09493a 100644 --- a/src/scripts/parallax.js +++ b/src/scripts/parallax.js @@ -1,6 +1,7 @@ import Rellax from 'rellax'; const PARALLAX_CLASS = '.js-parallax'; +const PARALLAX_BREAKPOINT = 1200; function initializeRellax() { return new Rellax(PARALLAX_CLASS, { @@ -14,14 +15,17 @@ function initializeRellax() { export default function init() { let rellax; - initializeRellax(); + + if (window.innerWidth > PARALLAX_BREAKPOINT) { + initializeRellax(); + } window.addEventListener('resize', () => { const width = window.innerWidth; - if (width >= 1200 && rellax === undefined) { + if (width >= PARALLAX_BREAKPOINT && rellax === undefined) { rellax = initializeRellax(); - } else if (rellax && rellax.destroy && width < 1200) { + } else if (rellax && rellax.destroy && width < PARALLAX_BREAKPOINT) { rellax.destroy(); rellax = undefined; }