Created
September 1, 2013 13:54
-
-
Save csakiistvan/6404611 to your computer and use it in GitHub Desktop.
Parallax, like stamfordglobal.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
Drupal.behaviors.parallaxScrolling = { | |
attach: function (context) { | |
$('[data-type]').each(function() { | |
$(this).data('offsetY', parseInt($(this).attr('data-offsetY'))); | |
$(this).data('speed', $(this).attr('data-speed')); | |
}); | |
$('div[data-type="background"]').each(function() { | |
var $self = $(this), | |
offsetCoords = $self.offset(), | |
topOffset = offsetCoords.top, | |
$window = $(window); | |
if ($(window).width() >= 800) { | |
$(window).scroll(function() { | |
if ( ($window.scrollTop() + $window.height()) > (topOffset) && ( (topOffset + $self.height()) > $window.scrollTop() ) ) { | |
var yPos = ((topOffset-$window.scrollTop()) / $self.data('speed')); | |
if ($self.data('offsetY')) { | |
yPos += $self.data('offsetY'); | |
} | |
var coords = '50% '+ yPos + 'px'; | |
$self.css({ backgroundPosition: coords }); | |
}; | |
}); | |
} | |
}); | |
} | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment