Created
April 15, 2016 12:22
-
-
Save Didier-Vaerman/579ee4ac337b44099d2d4f42c13a41be to your computer and use it in GitHub Desktop.
Parralax
This file contains hidden or 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
$( 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