diff --git a/lib/js/index.js b/lib/js/index.js index 0b55ea3..2ede2fb 100644 --- a/lib/js/index.js +++ b/lib/js/index.js @@ -1,17 +1,20 @@ // Parallax const depthFactor = 5; // Depth of the image wrt to the 0 z-index. Infinity being at the same distance as the rest of the content and 1 being as far away as possible. +const parallaxOffset = 20; $(window).on('scroll', () => { const movedBy = window.scrollY; + + if ($(window).height() - elem.getBoundingClientRect().top >= parallaxOffset) { + $('.parallax').each((i, parallax) => { + $(parallax).find('.parallax-layer').each((i, layer) => { + const depth = $(layer).attr('data-depth-factor') || depthFactor; // dynamically get depthFactor - $('.parallax').each((i, parallax) => { - $(parallax).find('.parallax-layer').each((i, layer) => { - const depth = $(layer).attr('data-depth-factor') || depthFactor; // dynamically get depthFactor - - $(layer).css({ - transform: `translateY(+${movedBy / depth}px)` // Move differently than the rest of the window + $(layer).css({ + transform: `translateY(+${movedBy / depth}px)` // Move differently than the rest of the window + }) }) }) - }) + } }) // /Parallax @@ -34,8 +37,8 @@ $(window).on('scroll', () => { const delay = $(elem).attr('data-fade-delay') || fadeDelay; if ($(window).height() - elem.getBoundingClientRect().top >= offset) { - $(elem).delay(delay).animate({opacity: 1}, duration).css({transition: `transform ${duration / 1000}s`}).css({transform: 'scale(1)'}); + $(elem).delay(delay).animate({opacity: 1}, duration).css({transition: `transform ${duration / 1000}s`}).css({transform: 'scale(1)'}).removeClass('scroll-fade'); } }) }) -// /ScrollFade Anim \ No newline at end of file +// /ScrollFade Anim