Fix parallax toggle

This commit is contained in:
Maciej Matuszewski 2018-01-18 07:56:38 +01:00
parent 9db307cd9b
commit b6be8a4048

View File

@ -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;
}