1 2/* 3 Plugin: jQuery Parallax 4 Version 1.1.3 5 Author: Ian Lunn 6 Twitter: @IanLunn 7 Author URL: http://www.ianlunn.co.uk/ 8 Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ 9 10 Dual licensed under the MIT and GPL licenses: 11 http://www.opensource.org/licenses/mit-license.php 12 http://www.gnu.org/licenses/gpl.html 13 */ 14 15(function( $ ){ 16 "use strict"; 17 18 var $window = $(window); 19 var windowHeight = $window.height(); 20 21 $window.resize(function () { 22 windowHeight = $window.height(); 23 }); 24 25 $.fn.parallax = function(xpos, speedFactor, outerHeight) { 26 var $this = $(this); 27 var getHeight; 28 var firstTop; 29 var paddingTop = 0; 30 31 //get the starting position of each element to have parallax applied to it 32 $this.each(function(){ 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.1; 49 if (arguments.length < 3 || outerHeight === null) outerHeight = true; 50 51 // function to be called whenever the window is scrolled or resized 52 function update(){ 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) + "px"); 66 }); 67 } 68 69 $window.bind('scroll', update).resize(update); 70 update(); 71 }; 72})(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.