Created
August 29, 2019 20:29
-
-
Save zdimaz/5f4dce2bcf320cdcd641525d3edd052b to your computer and use it in GitHub Desktop.
parralax jq fn
This file contains 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
$(document).ready(function(){ | |
$('section[data-type="background"]').each(function(){ | |
var $bgobj = $(this); // создаем объект | |
$(window).scroll(function() { | |
var ypos = -($window.scrolltop() / $bgobj.data('speed')); // вычисляем коэффициент | |
// присваиваем значение background-position | |
var coords = 'center '+ ypos + 'px'; | |
// создаем эффект parallax scrolling | |
$bgobj.css({ backgroundposition: coords }); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment