Created
December 9, 2017 05:45
-
-
Save sxidsvit/0cbff5f9fa207aa6a44e9fe23486b17d to your computer and use it in GitHub Desktop.
Background 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
| // 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