├── .DS_Store ├── .gitignore ├── README.markdown ├── bower.json ├── images ├── dot.png ├── firstBG.jpg ├── secondBG.jpg ├── thirdBG.jpg └── trainers.png ├── index.html ├── scripts ├── jquery.localscroll-1.2.7-min.js ├── jquery.parallax-1.1.3.js └── jquery.scrollTo-1.4.2-min.js └── style.css /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanLunn/jQuery-Parallax/cf5643b735683a5d8a5cd4afe7a8b02404774b1a/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | components -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | jQuery Parallax 2 | =============== 3 | 4 | jQuery Parallax is a script that simulates the parallax effect as seen on [nikebetterworld.com](http://www.nikebetterworld.com/). 5 | 6 | Plugin: jQuery Parallax 7 | Version: 1.1.3 8 | Author: [Ian Lunn](http://www.ianlunn.co.uk/) 9 | Twitter: [@IanLunn](http://www.twitter.com/IanLunn) 10 | Demo: [jQuery Vertical Parallax Demo](http://www.ianlunn.co.uk/plugins/jquery-parallax/) 11 | Tutorial: [Nikebetterworld Parallax Effect Demo](http://www.ianlunn.co.uk/blog/code-tutorials/recreate-nikebetterworld-parallax/) 12 | 13 | Dual licensed under the MIT and GPL licenses: 14 | http://www.opensource.org/licenses/mit-license.php 15 | http://www.gnu.org/licenses/gpl.html 16 | 17 | Updates 18 | ------- 19 | 20 | 12/6/2012 - Fixed a few demo bugs and made easier to use 21 | - Fixed a bug that prevented the third section from working 22 | - Removed the need to use the adjuster value 23 | 24 | 8/5/2012 - Fixed height/outerHeight parameter 25 | - Smoother effect when scrolling 26 | - Fixed positioning with scaled backgrounds 27 | - Reduced code 28 | - Now passes jsl 0.3.0 without warnings 29 | 30 | 26/10/2011 - Updated to work with jQuery 1.6.4 31 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-parallax", 3 | "version": "1.1.3", 4 | "main": "scripts/jquery.parallax.js", 5 | "dependencies": { 6 | "jquery": "~1.8.3", 7 | "jquery.scrollTo": "~1.4.6", 8 | "jquery.serialScroll": "*" 9 | }, 10 | "ignore": [ 11 | "**/.*", 12 | "node_modules", 13 | "components" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /images/dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanLunn/jQuery-Parallax/cf5643b735683a5d8a5cd4afe7a8b02404774b1a/images/dot.png -------------------------------------------------------------------------------- /images/firstBG.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanLunn/jQuery-Parallax/cf5643b735683a5d8a5cd4afe7a8b02404774b1a/images/firstBG.jpg -------------------------------------------------------------------------------- /images/secondBG.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanLunn/jQuery-Parallax/cf5643b735683a5d8a5cd4afe7a8b02404774b1a/images/secondBG.jpg -------------------------------------------------------------------------------- /images/thirdBG.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanLunn/jQuery-Parallax/cf5643b735683a5d8a5cd4afe7a8b02404774b1a/images/thirdBG.jpg -------------------------------------------------------------------------------- /images/trainers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanLunn/jQuery-Parallax/cf5643b735683a5d8a5cd4afe7a8b02404774b1a/images/trainers.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery Parallax Plugin Demo 6 | 7 | 8 | 9 | 10 | 11 | 26 | 27 | 28 | 29 | 35 | 36 |
37 |
38 |
39 |

(Almost) Static Background

40 |

This section has a background that moves slightly slower than the user scrolls. This is achieved by changing the top position of the background for every pixel the page is scrolled.

41 |
42 |
43 |
44 | 45 |
46 |
47 |
48 |

Multiple Backgrounds

49 |

The multiple backgrounds applied to this section are moved in a similar way to the first section -- every time the user scrolls down the page by a pixel, the positions of the backgrounds are changed.

50 |

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nibh erat, sagittis sit amet congue at, aliquam eu libero. Integer molestie, turpis vel ultrices facilisis, nisi mauris sollicitudin mauris, volutpat elementum enim urna eget odio. Donec egestas aliquet facilisis. Nunc eu nunc eget neque ornare fringilla. Nam vel sodales lectus. Nulla in pellentesque eros. Donec ultricies, enim vitae varius cursus, risus mauris iaculis neque, euismod sollicitudin metus erat vitae sapien. Sed pulvinar.

51 |
52 |
53 | 54 |
55 | 56 |
57 |
58 |
59 |

What Happens When JavaScript is Disabled?

60 |

The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.

61 |
62 |
63 |
64 | 65 |
66 |
67 |

Check out my new plugin Sequence.js for parallax effects and a whole lot more!

68 | 69 |

Ian Lunn

70 | 75 | 76 |

This demo is based on the Nikebetterworld.com website.

77 | 78 |

Credits

79 |

This plugin makes use of some scripts and images made by others:

80 | 87 |
88 |
89 | 90 | 91 | -------------------------------------------------------------------------------- /scripts/jquery.localscroll-1.2.7-min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * jQuery.LocalScroll - Animated scrolling navigation, using anchors. 3 | * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com 4 | * Dual licensed under MIT and GPL. 5 | * Date: 3/11/2009 6 | * @author Ariel Flesler 7 | * @version 1.2.7 8 | **/ 9 | ;(function($){var l=location.href.replace(/#.*/,'');var g=$.localScroll=function(a){$('body').localScroll(a)};g.defaults={duration:1e3,axis:'y',event:'click',stop:true,target:window,reset:true};g.hash=function(a){if(location.hash){a=$.extend({},g.defaults,a);a.hash=false;if(a.reset){var e=a.duration;delete a.duration;$(a.target).scrollTo(0,a);a.duration=e}i(0,location,a)}};$.fn.localScroll=function(b){b=$.extend({},g.defaults,b);return b.lazy?this.bind(b.event,function(a){var e=$([a.target,a.target.parentNode]).filter(d)[0];if(e)i(a,e,b)}):this.find('a,area').filter(d).bind(b.event,function(a){i(a,this,b)}).end().end();function d(){return!!this.href&&!!this.hash&&this.href.replace(this.hash,'')==l&&(!b.filter||$(this).is(b.filter))}};function i(a,e,b){var d=e.hash.slice(1),f=document.getElementById(d)||document.getElementsByName(d)[0];if(!f)return;if(a)a.preventDefault();var h=$(b.target);if(b.lock&&h.is(':animated')||b.onBefore&&b.onBefore.call(b,a,f,h)===false)return;if(b.stop)h.stop(true);if(b.hash){var j=f.id==d?'id':'name',k=$(' ').attr(j,d).css({position:'absolute',top:$(window).scrollTop(),left:$(window).scrollLeft()});f[j]='';$('body').prepend(k);location=e.hash;k.remove();f[j]=d}h.scrollTo(f,b).trigger('notify.serialScroll',[f])}})(jQuery); -------------------------------------------------------------------------------- /scripts/jquery.parallax-1.1.3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Plugin: jQuery Parallax 3 | Version 1.1.3 4 | Author: Ian Lunn 5 | Twitter: @IanLunn 6 | Author URL: http://www.ianlunn.co.uk/ 7 | Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ 8 | 9 | Dual licensed under the MIT and GPL licenses: 10 | http://www.opensource.org/licenses/mit-license.php 11 | http://www.gnu.org/licenses/gpl.html 12 | */ 13 | 14 | (function( $ ){ 15 | var $window = $(window); 16 | var windowHeight = $window.height(); 17 | 18 | $window.resize(function () { 19 | windowHeight = $window.height(); 20 | }); 21 | 22 | $.fn.parallax = function(xpos, speedFactor, outerHeight) { 23 | var $this = $(this); 24 | var getHeight; 25 | var firstTop; 26 | var paddingTop = 0; 27 | 28 | //get the starting position of each element to have parallax applied to it 29 | $this.each(function(){ 30 | firstTop = $this.offset().top; 31 | }); 32 | 33 | if (outerHeight) { 34 | getHeight = function(jqo) { 35 | return jqo.outerHeight(true); 36 | }; 37 | } else { 38 | getHeight = function(jqo) { 39 | return jqo.height(); 40 | }; 41 | } 42 | 43 | // setup defaults if arguments aren't specified 44 | if (arguments.length < 1 || xpos === null) xpos = "50%"; 45 | if (arguments.length < 2 || speedFactor === null) speedFactor = 0.1; 46 | if (arguments.length < 3 || outerHeight === null) outerHeight = true; 47 | 48 | // function to be called whenever the window is scrolled or resized 49 | function update(){ 50 | var pos = $window.scrollTop(); 51 | 52 | $this.each(function(){ 53 | var $element = $(this); 54 | var top = $element.offset().top; 55 | var height = getHeight($element); 56 | 57 | // Check if totally above or totally below viewport 58 | if (top + height < pos || top > pos + windowHeight) { 59 | return; 60 | } 61 | 62 | $this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); 63 | }); 64 | } 65 | 66 | $window.bind('scroll', update).resize(update); 67 | update(); 68 | }; 69 | })(jQuery); 70 | -------------------------------------------------------------------------------- /scripts/jquery.scrollTo-1.4.2-min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * jQuery.ScrollTo - Easy element scrolling using jQuery. 3 | * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com 4 | * Dual licensed under MIT and GPL. 5 | * Date: 5/25/2009 6 | * @author Ariel Flesler 7 | * @version 1.4.2 8 | * 9 | * http://flesler.blogspot.com/2007/10/jqueryscrollto.html 10 | */ 11 | ;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery); -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | /* 2 | Plugin: jQuery Parallax 3 | Version 1.1.3 4 | Author: Ian Lunn 5 | Twitter: @IanLunn 6 | Author URL: http://www.ianlunn.co.uk/ 7 | Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/ 8 | 9 | License: http://creativecommons.org/licenses/by-sa/3.0/ (Attribution Share Alike). Please attribute work to Ian Lunn simply by leaving these comments in the source code or if you'd prefer, place a link on your website to http://www.ianlunn.co.uk/. 10 | */ 11 | 12 | @charset "utf-8"; 13 | /* CSS Document */ 14 | 15 | body{ 16 | margin: 0; 17 | min-width: 980px; 18 | padding: 0; 19 | } 20 | 21 | p{ 22 | margin: 0 0 20px 0; 23 | } 24 | 25 | p, ul{ 26 | font-family:"Proxima Nova Light", 'Helvetica Neue', Arial, Helvetica, sans-serif; 27 | font-size-adjust:0.488; 28 | font-weight:200; 29 | font-style:normal; 30 | } 31 | 32 | img{ 33 | border: 0; 34 | } 35 | 36 | h1, #pixels{ 37 | font-family:"Museo 900", Verdana, serif; 38 | font-size-adjust:0.40; 39 | font-weight:700; 40 | font-style:normal; 41 | } 42 | 43 | h2{ 44 | font-family:"Beau Sans Pro Book", Verdana, sans-serif; 45 | font-size-adjust:0.531; 46 | font-weight:500; 47 | font-style:normal; 48 | } 49 | 50 | #header h1, #pixels{ 51 | color: #48941A; 52 | } 53 | 54 | .float-left{ 55 | float: left; 56 | margin: 0 0 0 20px; 57 | } 58 | 59 | .float-right{ 60 | float: right; 61 | margin: 0 20px 0 0; 62 | } 63 | 64 | .center{ 65 | font-size: 2.5em; 66 | padding: 80px 0 0 0; 67 | text-align: center; 68 | } 69 | 70 | #nav{ 71 | list-style: none; 72 | position: fixed; 73 | right: 20px; 74 | } 75 | 76 | #nav li{ 77 | margin: 0 0 15px 0; 78 | } 79 | 80 | #header, #intro, #second{ 81 | width: 100%; 82 | } 83 | 84 | #intro{ 85 | background:url(images/firstBG.jpg) 50% 0 no-repeat fixed; 86 | color: white; 87 | height: 600px; 88 | margin: 0 auto; 89 | padding: 0; 90 | } 91 | 92 | #second{ 93 | background: url(images/secondBG.jpg) 50% 0 no-repeat fixed; 94 | color: white; 95 | height: 1300px; 96 | margin: 0 auto; 97 | overflow: hidden; 98 | padding: 0; 99 | } 100 | 101 | #second .bg{ 102 | background: url(images/trainers.png) 50% 0 no-repeat fixed; 103 | height: 1300px; 104 | margin: 0 auto; 105 | padding: 0; 106 | position: absolute; 107 | width: 900px; 108 | z-index: 200; 109 | } 110 | 111 | #third{ 112 | background: url(images/thirdBG.jpg) 50% 0 no-repeat fixed; 113 | color: white; 114 | height: 650px; 115 | padding: 100px 0 0 0; 116 | } 117 | 118 | #fifth{ 119 | background: #ccc; 120 | height: 400px; 121 | margin: 0 auto; 122 | padding: 40px 0 0 0; 123 | } 124 | 125 | .story{ 126 | margin: 0 auto; 127 | min-width: 980px; 128 | overflow: auto; 129 | width: 980px; 130 | } 131 | 132 | .story .float-left, .story .float-right{ 133 | padding: 100px 0 0 0; 134 | position: relative; 135 | width: 350px; 136 | } 137 | --------------------------------------------------------------------------------