Last active
January 30, 2019 13:46
-
-
Save iamklim/32125821b02e3254319a0380cb1c01a7 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
function axelerateBackground(bgWrapperHeight) { | |
var $bgWrapper = $('.bg_wrapper'); //parallax block inside body with position fixed and css background | |
$(document).on('scroll', function() { | |
var dHeight = $(document).height(), | |
wHeight = $(window).height(), | |
imgHeight = bgWrapperHeight ? bgWrapperHeight : $bgWrapper.height(), //height of parallax block | |
coeff = (imgHeight - wHeight) / (dHeight - wHeight); //coefficient to avoid empty spaces on background | |
var shift = -1 * ($(window).scrollTop() * coeff); //size of shift on the top | |
if (dHeight - wHeight > 20) $bgWrapper.css('top', shift + "px"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment