Created
June 13, 2018 12:27
-
-
Save DevShahidul/49b6ae68d4e2513a3adc22c0cd6d9e1d to your computer and use it in GitHub Desktop.
See the example here >>> https://jsfiddle.net/vvup5ob5/3/ or see our work in Lam-v2 (Jun 2018) Link >> http://webtricker.com/projects/lam
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
| // Parallax effect | |
| if($(".parallax-section").length){ | |
| var winScrollTop=0; | |
| $.fn.is_on_screen = function(){ | |
| var win = $(window); | |
| var viewport = { | |
| top : win.scrollTop(), | |
| left : win.scrollLeft() | |
| }; | |
| //viewport.right = viewport.left + win.width(); | |
| viewport.bottom = viewport.top + win.height(); | |
| var bounds = this.offset(); | |
| //bounds.right = bounds.left + this.outerWidth(); | |
| bounds.bottom = bounds.top + this.outerHeight(); | |
| return (!(viewport.bottom < bounds.top || viewport.top > bounds.bottom)); | |
| }; | |
| function parallax() { | |
| var scrolled = $(window).scrollTop(); | |
| $('.parallax-section').each(function(){ | |
| if ($(this).is_on_screen()) { | |
| var firstTop = $(this).offset().top; | |
| var $span = $(this).find(".parallax-item"); | |
| var moveTop = (firstTop-winScrollTop) * 0.0815 //speed; | |
| $span.css("transform","translateY("+-moveTop+"px)"); | |
| } | |
| }); | |
| } | |
| $(window).scroll(function(e){ | |
| winScrollTop = $(this).scrollTop(); | |
| parallax(); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment