This repository has been archived by the owner on Jul 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fidian/master
Cleaned up code, fix a couple bugs
- Loading branch information
Showing
5 changed files
with
72 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters