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