Skip to content

Instantly share code, notes, and snippets.

@zdimaz
Created August 29, 2019 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdimaz/5f4dce2bcf320cdcd641525d3edd052b to your computer and use it in GitHub Desktop.
Save zdimaz/5f4dce2bcf320cdcd641525d3edd052b to your computer and use it in GitHub Desktop.
parralax jq fn
$(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