From d22186878fb927224a5e5b3445f3e390fe1b65a1 Mon Sep 17 00:00:00 2001 From: Alessandro Del Gobbo Date: Fri, 8 Nov 2013 22:09:33 +0100 Subject: [PATCH 01/14] Moved parameter parsing code to make them significative. Moved parameters parsing to top... elseway the parameter of this line were just completely ignored and replaced with default values. $('#parallax1').parallax("10%", 1.5); Now it works great! --- ...parallax-1.1.3.js => jquery.parallax-1.1.4.js} | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) rename scripts/{jquery.parallax-1.1.3.js => jquery.parallax-1.1.4.js} (95%) diff --git a/scripts/jquery.parallax-1.1.3.js b/scripts/jquery.parallax-1.1.4.js similarity index 95% rename from scripts/jquery.parallax-1.1.3.js rename to scripts/jquery.parallax-1.1.4.js index f3569dc..224bf4f 100644 --- a/scripts/jquery.parallax-1.1.3.js +++ b/scripts/jquery.parallax-1.1.4.js @@ -1,10 +1,11 @@ /* Plugin: jQuery Parallax -Version 1.1.3 +Version 1.1.4 Author: Ian Lunn Twitter: @IanLunn Author URL: http://www.ianlunn.co.uk/ Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ +Fixed by ADG - Alessandro del Gobbo - http://www.adg-idea.com Dual licensed under the MIT and GPL licenses: http://www.opensource.org/licenses/mit-license.php @@ -18,6 +19,7 @@ http://www.gnu.org/licenses/gpl.html $window.resize(function () { windowHeight = $window.height(); }); + $.fn.parallax = function(xpos, speedFactor, outerHeight) { var $this = $(this); @@ -25,6 +27,11 @@ http://www.gnu.org/licenses/gpl.html var firstTop; var paddingTop = 0; + // setup defaults if arguments aren't specified + 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; + //get the starting position of each element to have parallax applied to it $this.each(function(){ firstTop = $this.offset().top; @@ -39,11 +46,7 @@ http://www.gnu.org/licenses/gpl.html return jqo.height(); }; } - - // setup defaults if arguments aren't specified - 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 to be called whenever the window is scrolled or resized function update(){ From 326d97a4e764227ab656847285a495aab6346202 Mon Sep 17 00:00:00 2001 From: Alessandro Del Gobbo Date: Fri, 8 Nov 2013 22:12:11 +0100 Subject: [PATCH 02/14] Upgraded jQuery to 1.10 and the Parallax to 1.1.4 Upgraded jQuery to 1.10 and the Parallax to 1.1.4 --- index.html | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index 0a07d59..201411a 100755 --- a/index.html +++ b/index.html @@ -1,11 +1,11 @@ - + jQuery Parallax Plugin Demo - - + + + From 92bfa86cb57e3589f019155f8d60a9948082c81a Mon Sep 17 00:00:00 2001 From: Alessandro Del Gobbo Date: Sat, 16 Nov 2013 20:05:45 +0100 Subject: [PATCH 05/14] Added parameter to set the initial vertical position of Backgrounds Added support parameter to set the initial vertical position of Backgrounds --- scripts/jquery.parallax-1.1.4.js | 72 ---------------------------- scripts/jquery.parallax-1.1.5.js | 82 ++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 72 deletions(-) delete mode 100644 scripts/jquery.parallax-1.1.4.js create mode 100644 scripts/jquery.parallax-1.1.5.js diff --git a/scripts/jquery.parallax-1.1.4.js b/scripts/jquery.parallax-1.1.4.js deleted file mode 100644 index 224bf4f..0000000 --- a/scripts/jquery.parallax-1.1.4.js +++ /dev/null @@ -1,72 +0,0 @@ -/* -Plugin: jQuery Parallax -Version 1.1.4 -Author: Ian Lunn -Twitter: @IanLunn -Author URL: http://www.ianlunn.co.uk/ -Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ -Fixed by ADG - Alessandro del Gobbo - http://www.adg-idea.com - -Dual licensed under the MIT and GPL licenses: -http://www.opensource.org/licenses/mit-license.php -http://www.gnu.org/licenses/gpl.html -*/ - -(function( $ ){ - var $window = $(window); - var windowHeight = $window.height(); - - $window.resize(function () { - windowHeight = $window.height(); - }); - - - $.fn.parallax = function(xpos, speedFactor, outerHeight) { - var $this = $(this); - var getHeight; - var firstTop; - var paddingTop = 0; - - // setup defaults if arguments aren't specified - 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; - - //get the starting position of each element to have parallax applied to it - $this.each(function(){ - firstTop = $this.offset().top; - }); - - if (outerHeight) { - getHeight = function(jqo) { - return jqo.outerHeight(true); - }; - } else { - getHeight = function(jqo) { - return jqo.height(); - }; - } - - - // function to be called whenever the window is scrolled or resized - function update(){ - var pos = $window.scrollTop(); - - $this.each(function(){ - var $element = $(this); - var top = $element.offset().top; - var height = getHeight($element); - - // Check if totally above or totally below viewport - if (top + height < pos || top > pos + windowHeight) { - return; - } - - $this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); - }); - } - - $window.bind('scroll', update).resize(update); - update(); - }; -})(jQuery); diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js new file mode 100644 index 0000000..8116534 --- /dev/null +++ b/scripts/jquery.parallax-1.1.5.js @@ -0,0 +1,82 @@ +/* +Plugin: jQuery Parallax +Version 1.1.5 +Author: ADG Idea Alessandro del Gobbo (based on code of Ian Lunn) +Twitter: @alexoverflow +Author URL: http://www.adg-idea.com/ +Project on GitHub: https://github.com/aledelgo/jQuery-Parallax + +Dual licensed under the MIT and GPL licenses: +http://www.opensource.org/licenses/mit-license.php +http://www.gnu.org/licenses/gpl.html +*/ + +// USAGE: +// .parallax(xPosition, speedFactor, outerHeight) options: +//xPosition - Horizontal position of the element +//yPosition - Vertical initial position of the element (IN PIXELS!!!) +//inertia - speed to move relative to vertical scroll. Example: 0.1 is one tenth the speed of scrolling, 2 is twice the speed of scrolling +//outerHeight (true/false) - Whether or not jQuery should use it's outerHeight option to determine when a section is in the viewport +/*$('#intro').parallax("50%", null 0.1); + $('#second').parallax("50%", 30, 0.1);*/ + +(function( $ ){ + var $window = $(window); + var windowHeight = $window.height(); + + $window.resize(function () { + windowHeight = $window.height(); + }); + + $.fn.parallax = function(xpos, ypos, speedFactor, outerHeight) { + var $this = $(this); + var getHeight; + var firstTop; + var paddingTop = 0; + + // setup defaults if arguments aren't specified + if (arguments.length < 1 || xpos === null) xpos = "50%"; + if (arguments.length < 2 || ypos === null) ypos = "0"; + if (arguments.length < 3 || speedFactor === null) speedFactor = 0.5; + if (arguments.length < 4 || outerHeight === null) outerHeight = true; + + //get the starting position of each element to have parallax applied to it + function update (){ + + $this.each(function(){ + + firstTop = $this.offset().top; + }); + + if (outerHeight) { + getHeight = function(jqo) { + return jqo.outerHeight(true); + }; + } else { + getHeight = function(jqo) { + return jqo.height(); + }; + } + + // function to be called whenever the window is scrolled or resized + + var pos = $window.scrollTop(); + + $this.each(function(){ + var $element = $(this); + var top = $element.offset().top; + var height = getHeight($element); + + // Check if totally above or totally below viewport + if (top + height < pos || top > pos + windowHeight) { + return; + } + + $this.css('backgroundPosition', xpos + " " + Math.round(ypos + (firstTop - pos) * speedFactor) + "px"); + }); + } + + $window.bind('scroll', update).resize(update); + update(); + }; +})(jQuery); From 1066bca80ed94ef7c0f2051316eb4359802970c4 Mon Sep 17 00:00:00 2001 From: smart2k Date: Thu, 29 May 2014 20:26:10 +0400 Subject: [PATCH 06/14] Removed unused local variable. --- scripts/jquery.parallax-1.1.5.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js index 8116534..fde1889 100644 --- a/scripts/jquery.parallax-1.1.5.js +++ b/scripts/jquery.parallax-1.1.5.js @@ -32,7 +32,6 @@ http://www.gnu.org/licenses/gpl.html var $this = $(this); var getHeight; var firstTop; - var paddingTop = 0; // setup defaults if arguments aren't specified if (arguments.length < 1 || xpos === null) xpos = "50%"; From a0bb6fe5e77a2d34701cffae8301ba3bd8d53570 Mon Sep 17 00:00:00 2001 From: smart2k Date: Thu, 29 May 2014 20:31:25 +0400 Subject: [PATCH 07/14] single "var" per scope --- scripts/jquery.parallax-1.1.5.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js index fde1889..d608392 100644 --- a/scripts/jquery.parallax-1.1.5.js +++ b/scripts/jquery.parallax-1.1.5.js @@ -21,17 +21,17 @@ http://www.gnu.org/licenses/gpl.html $('#second').parallax("50%", 30, 0.1);*/ (function( $ ){ - var $window = $(window); - var windowHeight = $window.height(); + var $window = $(window), + windowHeight = $window.height(); $window.resize(function () { windowHeight = $window.height(); }); $.fn.parallax = function(xpos, ypos, speedFactor, outerHeight) { - var $this = $(this); - var getHeight; - var firstTop; + var $this = $(this), + getHeight, + firstTop; // setup defaults if arguments aren't specified if (arguments.length < 1 || xpos === null) xpos = "50%"; @@ -62,9 +62,9 @@ http://www.gnu.org/licenses/gpl.html var pos = $window.scrollTop(); $this.each(function(){ - var $element = $(this); - var top = $element.offset().top; - var height = getHeight($element); + var $element = $(this), + top = $element.offset().top, + height = getHeight($element); // Check if totally above or totally below viewport if (top + height < pos || top > pos + windowHeight) { From d23fbc552b5f18636b1ca8a54f5d7084612db569 Mon Sep 17 00:00:00 2001 From: smart2k Date: Thu, 29 May 2014 20:33:37 +0400 Subject: [PATCH 08/14] More efficient event binding --- scripts/jquery.parallax-1.1.5.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js index d608392..2d603bd 100644 --- a/scripts/jquery.parallax-1.1.5.js +++ b/scripts/jquery.parallax-1.1.5.js @@ -75,7 +75,7 @@ http://www.gnu.org/licenses/gpl.html }); } - $window.bind('scroll', update).resize(update); + $window.bind('scroll resize', update); update(); }; })(jQuery); From a5ade2f39b801b14fb0ab1f7d1e13f0efb0cf595 Mon Sep 17 00:00:00 2001 From: smart2k Date: Thu, 29 May 2014 20:52:37 +0400 Subject: [PATCH 09/14] Merged "each" iterators inside update() --- scripts/jquery.parallax-1.1.5.js | 52 ++++++++++++++------------------ 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js index 2d603bd..a0fe53b 100644 --- a/scripts/jquery.parallax-1.1.5.js +++ b/scripts/jquery.parallax-1.1.5.js @@ -38,41 +38,35 @@ http://www.gnu.org/licenses/gpl.html if (arguments.length < 2 || ypos === null) ypos = "0"; if (arguments.length < 3 || speedFactor === null) speedFactor = 0.5; if (arguments.length < 4 || outerHeight === null) outerHeight = true; + + if (outerHeight) { + getHeight = function(jqo) { + return jqo.outerHeight(true); + }; + } else { + getHeight = function(jqo) { + return jqo.height(); + }; + } //get the starting position of each element to have parallax applied to it function update (){ - + var pos = $window.scrollTop(); + $this.each(function(){ - + var $element = $(this), + top = $element.offset().top, + height = getHeight($element); + firstTop = $this.offset().top; + + // Check if totally above or totally below viewport + if (top + height < pos || top > pos + windowHeight) { + return; + } + + $this.css('backgroundPosition', xpos + " " + Math.round(ypos + (firstTop - pos) * speedFactor) + "px"); }); - - if (outerHeight) { - getHeight = function(jqo) { - return jqo.outerHeight(true); - }; - } else { - getHeight = function(jqo) { - return jqo.height(); - }; - } - - // function to be called whenever the window is scrolled or resized - - var pos = $window.scrollTop(); - - $this.each(function(){ - var $element = $(this), - top = $element.offset().top, - height = getHeight($element); - - // Check if totally above or totally below viewport - if (top + height < pos || top > pos + windowHeight) { - return; - } - - $this.css('backgroundPosition', xpos + " " + Math.round(ypos + (firstTop - pos) * speedFactor) + "px"); - }); } $window.bind('scroll resize', update); From 06d8ac51ddd41f5b2b6e25780c3a0bf75b8a4e37 Mon Sep 17 00:00:00 2001 From: smart2k Date: Thu, 29 May 2014 21:06:01 +0400 Subject: [PATCH 10/14] Setting of windowHeight functional encapsulation --- scripts/jquery.parallax-1.1.5.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js index a0fe53b..67ec381 100644 --- a/scripts/jquery.parallax-1.1.5.js +++ b/scripts/jquery.parallax-1.1.5.js @@ -22,11 +22,11 @@ http://www.gnu.org/licenses/gpl.html (function( $ ){ var $window = $(window), - windowHeight = $window.height(); + windowHeight; $window.resize(function () { - windowHeight = $window.height(); - }); + windowHeight = $(this).height(); + }).triggerHandler('resize'); $.fn.parallax = function(xpos, ypos, speedFactor, outerHeight) { var $this = $(this), @@ -48,7 +48,7 @@ http://www.gnu.org/licenses/gpl.html return jqo.height(); }; } - + //get the starting position of each element to have parallax applied to it function update (){ var pos = $window.scrollTop(); @@ -67,9 +67,8 @@ http://www.gnu.org/licenses/gpl.html $this.css('backgroundPosition', xpos + " " + Math.round(ypos + (firstTop - pos) * speedFactor) + "px"); }); - } + } - $window.bind('scroll resize', update); - update(); + $window.bind('scroll resize', update).triggerHandler('scroll'); }; })(jQuery); From f5633dc2df92318304d317014f9f127fb9593cb3 Mon Sep 17 00:00:00 2001 From: smart2k Date: Thu, 29 May 2014 21:14:48 +0400 Subject: [PATCH 11/14] Don't need to use named function for event handling. --- scripts/jquery.parallax-1.1.5.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js index 67ec381..4a850a9 100644 --- a/scripts/jquery.parallax-1.1.5.js +++ b/scripts/jquery.parallax-1.1.5.js @@ -49,8 +49,8 @@ http://www.gnu.org/licenses/gpl.html }; } - //get the starting position of each element to have parallax applied to it - function update (){ + //get the starting position of each element to have parallax applied to it + $window.bind('scroll resize', function (){ var pos = $window.scrollTop(); $this.each(function(){ @@ -67,8 +67,6 @@ http://www.gnu.org/licenses/gpl.html $this.css('backgroundPosition', xpos + " " + Math.round(ypos + (firstTop - pos) * speedFactor) + "px"); }); - } - - $window.bind('scroll resize', update).triggerHandler('scroll'); + }).triggerHandler('scroll'); }; })(jQuery); From 9d0551f1364284d0a75555640bafa2a4b6fdf9bc Mon Sep 17 00:00:00 2001 From: smart2k Date: Thu, 29 May 2014 22:06:27 +0400 Subject: [PATCH 12/14] Default "YPos" value type changed to an integer. --- scripts/jquery.parallax-1.1.5.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js index 4a850a9..b32e737 100644 --- a/scripts/jquery.parallax-1.1.5.js +++ b/scripts/jquery.parallax-1.1.5.js @@ -35,7 +35,7 @@ http://www.gnu.org/licenses/gpl.html // setup defaults if arguments aren't specified if (arguments.length < 1 || xpos === null) xpos = "50%"; - if (arguments.length < 2 || ypos === null) ypos = "0"; + if (arguments.length < 2 || ypos === null) ypos = 0; if (arguments.length < 3 || speedFactor === null) speedFactor = 0.5; if (arguments.length < 4 || outerHeight === null) outerHeight = true; From f7712558278ff239dbe2297f49752d6daef80878 Mon Sep 17 00:00:00 2001 From: smart2k Date: Fri, 30 May 2014 13:46:31 +0400 Subject: [PATCH 13/14] Default values definition, cleaner way --- scripts/jquery.parallax-1.1.5.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js index b32e737..3a0dc13 100644 --- a/scripts/jquery.parallax-1.1.5.js +++ b/scripts/jquery.parallax-1.1.5.js @@ -34,10 +34,10 @@ http://www.gnu.org/licenses/gpl.html firstTop; // setup defaults if arguments aren't specified - if (arguments.length < 1 || xpos === null) xpos = "50%"; - if (arguments.length < 2 || ypos === null) ypos = 0; - if (arguments.length < 3 || speedFactor === null) speedFactor = 0.5; - if (arguments.length < 4 || outerHeight === null) outerHeight = true; + xpos = xpos || "50%"; + ypos = ypos || 0; + speedFactor = speedFactor || 0.5; + outerHeight = outerHeight || true; if (outerHeight) { getHeight = function(jqo) { From 41a736ecc1b883c035463430f5ae733322fa3c78 Mon Sep 17 00:00:00 2001 From: smart2k Date: Fri, 30 May 2014 14:12:32 +0400 Subject: [PATCH 14/14] Checking outerHeight definition before setting default value --- scripts/jquery.parallax-1.1.5.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/jquery.parallax-1.1.5.js b/scripts/jquery.parallax-1.1.5.js index 3a0dc13..19094df 100644 --- a/scripts/jquery.parallax-1.1.5.js +++ b/scripts/jquery.parallax-1.1.5.js @@ -37,7 +37,10 @@ http://www.gnu.org/licenses/gpl.html xpos = xpos || "50%"; ypos = ypos || 0; speedFactor = speedFactor || 0.5; - outerHeight = outerHeight || true; + + if (typeof outerHeight === 'undefined') { + outerHeight = true; + } if (outerHeight) { getHeight = function(jqo) {