Last active
August 29, 2015 14:03
-
-
Save vladimirlukyanov/3031a19cdcc3c02ecd59 to your computer and use it in GitHub Desktop.
Parallax
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
<section id="home" data-type="background" data-speed="10" class="pages"> | |
<article class="bg">Простая техника Parallax Scrolling</article> | |
</section> | |
<section id="about" data-type="background" data-speed="10" class="pages"> | |
<article class="bg">Простая техника Parallax Scrolling</article> | |
</section> |
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
$('.parallax').each(function () { | |
var bgobj = $(this).find('.bg'); // создаем объект | |
$(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