Skip to content
This repository was archived by the owner on Jul 27, 2020. It is now read-only.

Added Horizontal Moving #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Parallax Plugin Demo</title>
Expand All @@ -16,8 +16,8 @@
//xPosition - Horizontal position of the element
//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%", 0.1);
$('#second').parallax("50%", 0.1);
$('#intro').parallax("50%", 0.1, true, true, "left", 0.1);
$('#second').parallax("50%", 0.1);
$('.bg').parallax("50%", 0.4);
$('#third').parallax("50%", 0.3);

Expand Down Expand Up @@ -63,17 +63,17 @@ <h2>What Happens When JavaScript is Disabled?</h2>
</div> <!--#third-->

<div id="fifth">
<div class="story">
<div class="story">
<p>Check out my new plugin <a href="http://www.sequencejs.com" title="Sequence.js">Sequence.js</a> for parallax effects and a whole lot more!</p>

<h2>Ian Lunn</h2>
<ul>
<li><strong>Twitter</strong>: <a href="http://www.twitter.com/IanLunn" title="Follow Ian on Twitter">@IanLunn</a></li>
<li><strong>GitHub</strong>: <a href="http://www.github.com/IanLunn" title="Follow Ian on GitHub">IanLunn</a></li>
<li><strong>Website</strong>: <a href="http://www.ianlunn.co.uk/" title="Ian Lunn Design">www.ianlunn.co.uk</a></li>
</ul>

<p>This demo is based on the <a href="http://www.nikebetterworld.com" title="Nike Better World">Nikebetterworld.com</a> website.</p>
<h2>Ian Lunn</h2>
<ul>
<li><strong>Twitter</strong>: <a href="http://www.twitter.com/IanLunn" title="Follow Ian on Twitter">@IanLunn</a></li>
<li><strong>GitHub</strong>: <a href="http://www.github.com/IanLunn" title="Follow Ian on GitHub">IanLunn</a></li>
<li><strong>Website</strong>: <a href="http://www.ianlunn.co.uk/" title="Ian Lunn Design">www.ianlunn.co.uk</a></li>
</ul>
<p>This demo is based on the <a href="http://www.nikebetterworld.com" title="Nike Better World">Nikebetterworld.com</a> website.</p>

<h2>Credits</h2>
<p>This plugin makes use of some scripts and images made by others:</p>
Expand Down
23 changes: 21 additions & 2 deletions scripts/jquery.parallax-1.1.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(){
Expand All @@ -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");
}
});
}

Expand Down