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

Commit

Permalink
Merge pull request #1 from fidian/master
Browse files Browse the repository at this point in the history
Cleaned up code, fix a couple bugs
  • Loading branch information
IanLunn committed Jun 11, 2012
2 parents 1ee33a2 + dabf9a7 commit 7d5113c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 91 deletions.
10 changes: 8 additions & 2 deletions 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.1
Version: 1.1.2
Author: [Ian Lunn](http://www.ianlunn.co.uk/)
Demo: [jQuery Vertical Parallax Demo](http://www.ianlunn.co.uk/plugins/jquery-parallax/)
Tutorial: [Nikebetterworld Parallax Effect Demo](http://www.ianlunn.co.uk/blog/code-tutorials/recreate-nikebetterworld-parallax/)
Expand All @@ -16,4 +16,10 @@ http://www.gnu.org/licenses/gpl.html
Updates
-------

26/10/2011 - Updated to work with jQuery 1.6.4
8/5/2012 - Fixed height/outerHeight parameter
- Smoother effect when scrolling
- Fixed positioning with scaled backgrounds
- Reduced code
- Now passes jsl 0.3.0 without warnings

26/10/2011 - Updated to work with jQuery 1.6.4
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<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.js"></script>
<script type="text/javascript" src="scripts/jquery.parallax-1.1.2.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 Down
61 changes: 61 additions & 0 deletions scripts/jquery.parallax-1.1.2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Plugin: jQuery Parallax
Version 1.1.2
Author: Ian Lunn
Author URL: http://www.ianlunn.co.uk/
Plugin URL: http://www.ianlunn.co.uk/plugins/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
*/

(function( $ ){
var $window = $(window);
var windowHeight = $window.height();

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

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

if (outerHeight) {
getHeight = function(jqo) {
return jqo.outerHeight(true);
};
} else {
getHeight = function(jqo) {
return jqo.height();
};
}

// setup defaults if arguments aren't specified
if (arguments.length < 1 || xpos === null) xpos = "50%";
if (arguments.length < 2 || adjuster === null) adjuster = 0;
if (arguments.length < 3 || speedFactor === null) speedFactor = 0.1;

// 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((adjuster - pos + top) * speedFactor) + "px");
});
}

$window.bind('scroll', update).resize(update);
update();
};
})( jQuery );
86 changes: 0 additions & 86 deletions scripts/jquery.parallax-1.1.js

This file was deleted.

4 changes: 2 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Plugin: jQuery Parallax
Version 1.1
Version 1.1.2
Author: Ian Lunn
Author URL: http://www.ianlunn.co.uk/
Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/
Expand Down Expand Up @@ -132,4 +132,4 @@ h2{
padding: 100px 0 0 0;
position: relative;
width: 350px;
}
}

0 comments on commit 7d5113c

Please sign in to comment.