Skip to content

Instantly share code, notes, and snippets.

@sxidsvit
Created December 9, 2017 05:45
Show Gist options
  • Select an option

  • Save sxidsvit/0cbff5f9fa207aa6a44e9fe23486b17d to your computer and use it in GitHub Desktop.

Select an option

Save sxidsvit/0cbff5f9fa207aa6a44e9fe23486b17d to your computer and use it in GitHub Desktop.
Background Parallax - классический параллакс фона
// Background Parallax
var $window = $(window);
if($('section[data-type="background"]').length){
$('section[data-type="background"]').each(function(){
var $obj = $(this);
var offset = $obj.offset().top;
$(window).scroll(function()
{
offset = $obj.offset().top;
if ($window.scrollTop() > (offset - window.innerHeight))
{
var yPos = -(($window.scrollTop() - offset) / 5 );
var coords = '50% ' + ( yPos ) + 'px';
$obj.css({ backgroundPosition: coords });
}
});
$(window).resize(function()
{
offset = $obj.offset().top;
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment