1(function( $ ){ 2 var $window = $(window); 3 var windowHeight = $window.height(); 4 5 $window.resize(function () { 6 windowHeight = $window.height(); 7 }); 8 9 $.fn.parallax = function(xpos, speedFactor, outerHeight) { 10 var $this = $(this); 11 var getHeight; 12 var firstTop; 13 var paddingTop = 0; 14 15 //get the starting position of each element to have parallax applied to it 16 $this.each(function(){ 17 firstTop = $this.offset().top; 18 }); 19 20 if (outerHeight) { 21 getHeight = function(jqo) { 22 return jqo.outerHeight(true); 23 }; 24 } else { 25 getHeight = function(jqo) { 26 return jqo.height(); 27 }; 28 } 29 30 // setup defaults if arguments aren't specified 31 if (arguments.length < 1 || xpos === null) xpos = "50%"; 32 if (arguments.length < 2 || speedFactor === null) speedFactor = 0.1; 33 if (arguments.length < 3 || outerHeight === null) outerHeight = true; 34 35 // function to be called whenever the window is scrolled or resized 36 function update(){ 37 var pos = $window.scrollTop(); 38 39 $this.each(function(){ 40 var $element = $(this); 41 var top = $element.offset().top; 42 var height = getHeight($element); 43 44 // Check if totally above or totally below viewport 45 if (top + height < pos || top > pos + windowHeight) { 46 return; 47 } 48 49 $this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); 50 }); 51 } 52 53 $window.bind('scroll', update).resize(update); 54 update(); 55 }; 56})(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.