Last active
July 25, 2016 11:12
-
-
Save madsleejensen/d7dc88945d7d3756fc38778b23d313b3 to your computer and use it in GitHub Desktop.
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
<script> | |
// place in "FOOTER" custom code in webflow admin. | |
Webflow.push(function() { | |
function runParallax() { | |
var top = $(window).scrollTop(); | |
var height = $(window).height(); | |
$('.section, .hero-section').each(function() { | |
var element = $(this); | |
var distanceFromTop = element.offset().top - top; | |
var percentage = (distanceFromTop / height); | |
var rangeInPercentage = parseInt(element.attr('data-parallax-range')) || 20; | |
var calculatedPercentage = percentage * rangeInPercentage; | |
var positionY = 50 + (calculatedPercentage); | |
element.css('background-position-y', positionY.toString() + '%'); | |
}); | |
} | |
jQuery(window).on('scroll', runParallax); | |
jQuery(window).on('resize', runParallax); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment