Skip to content

Instantly share code, notes, and snippets.

@Didier-Vaerman
Created April 15, 2016 12:22
Show Gist options
  • Save Didier-Vaerman/579ee4ac337b44099d2d4f42c13a41be to your computer and use it in GitHub Desktop.
Save Didier-Vaerman/579ee4ac337b44099d2d4f42c13a41be to your computer and use it in GitHub Desktop.
Parralax
$( window ).scroll(function(){
$('.banner-image[data-perspective]').each(function(){
var perspective = $(this).data('perspective');
var position = $(this).parents().position();
var scrollTop = position.top - $(window).scrollTop();
var height = $(this).outerHeight();
var calc = $(this).outerHeight() - height - scrollTop ;
$(this).css({'transform': 'translate3d(0px, ' + Math.round(calc/perspective) + 'px, 0px)'});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment