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
(function( $ ){"use strict"; var $window = $(window); var windowHeight = $window.height(); $window.resize(function () {windowHeight = $window.height(); }
14
); $.fn.parallax = function(xpos, speedFactor, outerHeight) {var $this = $(this); var getHeight; var firstTop; var paddingTop = 0; $this.each(function(){firstTop = $this.offset().top; }
15
); if (outerHeight) {getHeight = function(jqo) {return jqo.outerHeight(true); }
16
; }
17
else {getHeight = function(jqo) {return jqo.height(); }
18
; }
19
if (arguments.length < 1 || xpos === null) xpos = "50%"; if (arguments.length < 2 || speedFactor === null) speedFactor = 0.1; if (arguments.length < 3 || outerHeight === null) outerHeight = true; function update(){var pos = $window.scrollTop(); $this.each(function(){var $element = $(this); var top = $element.offset().top; var height = getHeight($element); if (top + height < pos || top > pos + windowHeight) {return; }
20
$this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); }
21
); }
22
$window.bind('scroll', update).resize(update); update(); }
23
; }
24
)(jQuery);