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

Script fixed #9

Open
wants to merge 15 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
5 changes: 4 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jQuery Parallax
jQuery Parallax is a script that simulates the parallax effect as seen on [nikebetterworld.com](http://www.nikebetterworld.com/).

Plugin: jQuery Parallax
Version: 1.1.3
Version: 1.1.4
Author: [Ian Lunn](http://www.ianlunn.co.uk/)
Twitter: [@IanLunn](http://www.twitter.com/IanLunn)
Demo: [jQuery Vertical Parallax Demo](http://www.ianlunn.co.uk/plugins/jquery-parallax/)
Expand All @@ -17,6 +17,9 @@ http://www.gnu.org/licenses/gpl.html
Updates
-------

08/11/2013 - Fixed parameter parsing and upgraded to jQuery 1.10.1
Fix by [ADG - Alessandro del Gobbo](http://www.adg-idea.com)

12/6/2012 - Fixed a few demo bugs and made easier to use
- Fixed a bug that prevented the third section from working
- Removed the need to use the adjuster value
Expand Down
31 changes: 16 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<!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>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.parallax-1.1.3.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="scripts/jquery.parallax-1.1.4.js"></script>
<script type="text/javascript" src="scripts/jquery.localscroll-1.2.7-min.js"></script>
<script type="text/javascript" src="scripts/jquery.scrollTo-1.4.2-min.js"></script>
<script type="text/javascript">
Expand All @@ -16,8 +17,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);
$('#second').parallax("50%", 0.1);
$('.bg').parallax("50%", 0.4);
$('#third').parallax("50%", 0.3);

Expand Down Expand Up @@ -63,17 +64,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
69 changes: 0 additions & 69 deletions scripts/jquery.parallax-1.1.3.js

This file was deleted.

75 changes: 75 additions & 0 deletions scripts/jquery.parallax-1.1.5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
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),
windowHeight;

$window.resize(function () {
windowHeight = $(this).height();
}).triggerHandler('resize');

$.fn.parallax = function(xpos, ypos, speedFactor, outerHeight) {
var $this = $(this),
getHeight,
firstTop;

// setup defaults if arguments aren't specified
xpos = xpos || "50%";
ypos = ypos || 0;
speedFactor = speedFactor || 0.5;

if (typeof outerHeight === 'undefined') {
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
$window.bind('scroll resize', function (){
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");
});
}).triggerHandler('scroll');
};
})(jQuery);