/*<br /> * Lulu Parallax v1.0<br /> *<br /> * Copyright 2016 Carlos Ruiz / carlosruiz.me<br /> *<br /> */<br /> <br /> function luluParallax() {<br /> // Setup<br /> var viewportHeight = $(window).height();<br /> $('.parallax-container').each(function() {<br /> var groupHeight = $(this).parent('.parallax-group').height();<br /> // Make adjustments if a FOREGROUND container is taller than its GROUP container<br /> if ($(this).hasClass('foreground') && (groupHeight < $(this).outerHeight())) {<br /> var groupHeight = $(this).outerHeight();<br /> $(this).parent('.parallax-group').css('height', groupHeight);<br /> $(this).parent('.parallax-group').find('.background').css('min-height', groupHeight);<br /> }<br /> var groupTopFixed = Math.round($(this).parent('.parallax-group').offset().top);<br /> var containerHeight = $(this).outerHeight();<br /> // Store values<br /> $(this).data('lp', {<br /> gh: groupHeight,<br /> gtf: groupTopFixed,<br /> ch: containerHeight<br /> });<br /> });<br /> // Action <br /> $(window).scroll(function() {<br /> var scrollPosition = $(window).scrollTop();<br /> $('.parallax-container').each(function() {<br /> var groupTopRelative = Math.round($(this).data('lp').gtf - scrollPosition);<br /> var fgPosition = Math.min(<br /> ($(this).data('lp').gh - $(this).data('lp').ch),<br /> (-(groupTopRelative - Math.min(viewportHeight, $(this).data('lp').gtf)) * $(this).data('rate'))<br /> );<br /> var bgPosition = Math.max(<br /> ($(this).data('lp').gh - $(this).data('lp').ch),<br /> ((groupTopRelative - Math.min(viewportHeight, $(this).data('lp').gtf)) * $(this).data('rate'))<br /> );<br /> // Make sure that the GROUP container is in the VIEWPORT<br /> if (groupTopRelative <= viewportHeight) {<br /> if ($(this).hasClass('against') && $(this).hasClass('foreground')) {<br /> $(this).css(<br /> 'bottom',<br /> fgPosition<br /> );<br /> } else if ($(this).hasClass('with') && $(this).hasClass('foreground')) {<br /> $(this).css(<br /> 'top',<br /> fgPosition<br /> );<br /> } else if ($(this).hasClass('against') && $(this).hasClass('background')) {<br /> $(this).css(<br /> 'top',<br /> bgPosition<br /> );<br /> } else if ($(this).hasClass('with') && $(this).hasClass('background')) {<br /> $(this).css(<br /> 'bottom',<br /> bgPosition<br /> );<br /> }<br /> }<br /> });<br /> }); <br /> }