Sha256: 5375f9f62fd8c9aaaba9ebca276180df1f102f575fff294e15ff56c15bcc25ba
Contents?: true
Size: 1.84 KB
Versions: 3
Compression:
Stored size: 1.84 KB
Contents
(function ($) { $.fn.parallax = function () { var window_width = $(window).width(); // Parallax Scripts return this.each(function(i) { var $this = $(this); $this.addClass('parallax'); function updateParallax(initial) { var container_height; if (window_width < 601) { container_height = ($this.height() > 0) ? $this.height() : $this.children("img").height(); } else { container_height = ($this.height() > 0) ? $this.height() : 500; } var $img = $this.children("img").first(); var img_height = $img.height(); var parallax_dist = img_height - container_height; var bottom = $this.offset().top + container_height; var top = $this.offset().top; var scrollTop = $(window).scrollTop(); var windowHeight = window.innerHeight; var windowBottom = scrollTop + windowHeight; var percentScrolled = (windowBottom - top) / (container_height + windowHeight); var parallax = Math.round((parallax_dist * percentScrolled)); if (initial) { $img.css('display', 'block'); } if ((bottom > scrollTop) && (top < (scrollTop + windowHeight))) { $img.css('transform', "translate3D(-50%," + parallax + "px, 0)"); } } // Wait for image load $this.children("img").one("load", function() { updateParallax(true); }).each(function() { if (this.complete) $(this).trigger("load"); }); $(window).scroll(function() { window_width = $(window).width(); updateParallax(false); }); $(window).resize(function() { window_width = $(window).width(); updateParallax(false); }); }); }; }( jQuery ));
Version data entries
3 entries across 3 versions & 3 rubygems
Version | Path |
---|---|
mtl-1.1.0 | vendor/assets/javascripts/materialize/parallax.js |
dr-jekylls-materials-0.1.5 | assets/js/parallax.js |
materialize-sass-0.97.8 | app/assets/javascripts/materialize/parallax.js |