Skip to content

Instantly share code, notes, and snippets.

@csakiistvan
Created September 1, 2013 13:54
Show Gist options
  • Save csakiistvan/6404611 to your computer and use it in GitHub Desktop.
Save csakiistvan/6404611 to your computer and use it in GitHub Desktop.
Parallax, like stamfordglobal.com
(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