Last active
October 2, 2018 09:07
-
-
Save khripunovpp/56d526631489a53458ff0ee8846397b7 to your computer and use it in GitHub Desktop.
parallax
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
var parallax = function() { | |
$(window).on('scroll', function() { | |
var st = $(window).scrollTop(); | |
$('.js-parallax-container').each(function() { | |
var containerOffset = $(this).offset(), | |
containerOffsetTop = containerOffset.top, | |
containerHeight = $(this).outerHeight(); | |
scrollTop = (st - containerOffsetTop) + (containerHeight/4); // ставим точку отсчета паралакса от середины контейнера | |
$('.js-parallax', this).each(function() { | |
var speed = 10, | |
reverse = $(this).data('reverse'), | |
shift = scrollTop / speed; | |
if ($(this).data('reverse') === true) shift = -shift; | |
$(this).css({ | |
"transform": "translate(0%, " + shift + "%" | |
}) | |
}); | |
}) | |
}); | |
} | |
$(function() { | |
parallax() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment