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