Check out my new plugin Sequence.js for parallax effects and a whole lot more!
- -Ian Lunn
--
-
- Twitter: @IanLunn -
- GitHub: IanLunn -
- Website: www.ianlunn.co.uk -
This demo is based on the Nikebetterworld.com website.
+ +Ian Lunn
+-
+
- Twitter: @IanLunn +
- GitHub: IanLunn +
- Website: www.ianlunn.co.uk +
This demo is based on the Nikebetterworld.com website.
Credits
This plugin makes use of some scripts and images made by others:
diff --git a/scripts/jquery.parallax-1.1.3.js b/scripts/jquery.parallax-1.1.3.js index f3569dc..14c8119 100644 --- a/scripts/jquery.parallax-1.1.3.js +++ b/scripts/jquery.parallax-1.1.3.js @@ -19,7 +19,7 @@ http://www.gnu.org/licenses/gpl.html windowHeight = $window.height(); }); - $.fn.parallax = function(xpos, speedFactor, outerHeight) { + $.fn.parallax = function(xpos, speedFactor, outerHeight, xMove, xDirection, xSpeedFactor) { var $this = $(this); var getHeight; var firstTop; @@ -44,6 +44,9 @@ http://www.gnu.org/licenses/gpl.html 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; + if (arguments.length < 4 || xMove === null) xMove = false; + if (arguments.length < 5 || xDirection === null) xDirection = "right"; + if (arguments.length < 6 || xSpeedFactor === null) xSpeedFactor = 0.5; // function to be called whenever the window is scrolled or resized function update(){ @@ -59,7 +62,23 @@ http://www.gnu.org/licenses/gpl.html return; } - $this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); + //Move horizontally if specified + if (xMove === true & xDirection === "right"){ + xpos = Math.round((firstTop + pos) * xSpeedFactor); + } + else if(xMove === true & xDirection === "left"){ + xpos = Math.round((firstTop - pos) * xSpeedFactor); + } + else{ + return; + } + + if(xMove === true){ + $this.css('backgroundPosition', xpos + "px " + Math.round((firstTop - pos) * speedFactor) + "px"); + } + else{ + $this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); + } }); }