1/* 2 Plugin: jQuery Parallax 3 Version 1.1.3 4 Author: Ian Lunn 5 Twitter: @IanLunn 6 Author URL: http://www.ianlunn.co.uk/ 7 Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ 8 9 Dual licensed under the MIT and GPL licenses: 10 http://www.opensource.org/licenses/mit-license.php 11 http://www.gnu.org/licenses/gpl.html 12 */ 13 14(function( $ ){ 15 "use strict"; 16 17 var $window = $(window); 18 var windowHeight = $window.height(); 19 20 $window.resize(function () { 21 windowHeight = $window.height(); 22 }); 23 24 $.fn.parallax = function(xpos, speedFactor, outerHeight) { 25 var $this = $(this); 26 var getHeight; 27 var firstTop; 28 var paddingTop = 0; 29 30 //get the starting position of each element to have parallax applied to it 31 $this.each(function(){ 32 firstTop = $this.offset().top; 33 }); 34 35 if (outerHeight) { 36 getHeight = function(jqo) { 37 return jqo.outerHeight(true); 38 }; 39 } else { 40 getHeight = function(jqo) { 41 return jqo.height(); 42 }; 43 } 44 45 // setup defaults if arguments aren't specified 46 if (arguments.length < 1 || xpos === null) xpos = "50%"; 47 if (arguments.length < 2 || speedFactor === null) speedFactor = 0.1; 48 if (arguments.length < 3 || outerHeight === null) outerHeight = true; 49 50 // function to be called whenever the window is scrolled or resized 51 function update(){ 52 var pos = $window.scrollTop(); 53 54 $this.each(function(){ 55 var $element = $(this); 56 var top = $element.offset().top; 57 var height = getHeight($element); 58 59 // Check if totally above or totally below viewport 60 if (top + height < pos || top > pos + windowHeight) { 61 return; 62 } 63 64 $this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); 65 }); 66 } 67 68 $window.bind('scroll', update).resize(update); 69 update(); 70 }; 71})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.