Permalink
Browse files

jQuery Parallax 1.1 Commit

  • Loading branch information...
0 parents commit 0968752d419d1901a7704d5b352fd35e1f5186bf @IanLunn committed Oct 19, 2011
BIN .DS_Store
Binary file not shown.
BIN images/dot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/firstBG.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/secondBG.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/thirdBG.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/trainers.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 index.html
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<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.5.1/jquery.min.js"></script>
+<script type="text/javascript" src="scripts/jquery.parallax-1.1.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">
+$(document).ready(function(){
+ $('#nav').localScroll(800);
+
+ RepositionNav();
+
+ $(window).resize(function(){
+ RepositionNav();
+ });
+
+ //.moveRelative() options:
+ //x position
+ //adjuster (y position to start from)
+ //inertia (speed to move relative to vertical scroll)
+ //outerHeight (true/false)
+ $('#intro, #second').moveRelative("50%", 0, 0.1, true);
+ $('#third').moveRelative("50%", 2750, 0.3, true);
+ $('.bg').moveRelative("50%", 2150, 0.4, true);
+
+})
+</script>
+</head>
+
+<body>
+ <ul id="nav">
+ <li><a href="#intro" title="Next Section"><img src="images/dot.png" alt="Link" /></a></li>
+ <li><a href="#second" title="Next Section"><img src="images/dot.png" alt="Link" /></a></li>
+ <li><a href="#third" title="Next Section"><img src="images/dot.png" alt="Link" /></a></li>
+ <li><a href="#fifth" title="Next Section"><img src="images/dot.png" alt="Link" /></a></li>
+ </ul>
+
+ <div id="intro">
+ <div class="story">
+ <div class="float-left">
+ <h2>(Almost) Static Background</h2>
+ <p>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.</p>
+ </div>
+ </div> <!--.story-->
+ </div> <!--#intro-->
+
+ <div id="second">
+ <div class="story"><div class="bg"></div>
+ <div class="float-right">
+ <h2>Multiple Backgrounds</h2>
+ <p>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.</p>
+ <p>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.</p>
+ </div>
+ </div> <!--.story-->
+
+ </div> <!--#second-->
+
+ <div id="third">
+ <div class="story">
+ <div class="float-left">
+ <h2>What Happens When JavaScript is Disabled?</h2>
+ <p>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.</p>
+ </div>
+ </div> <!--.story-->
+ </div> <!--#third-->
+
+ <div id="fifth">
+ <div class="story">
+ <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>
+ <ul>
+ <li><a href="http://flesler.blogspot.com/2007/10/jqueryscrollto.html" title="jQuery ScrollTo">jQuery ScrollTo</a></li>
+ <li><a href="http://www.fontdeck.com/" title="Licensed fonts from FontDeck">Licensed fonts from FontDeck</a></li>
+ <li><a href="http://downloads.dvq.co.nz/" title="Background Textures">Wooden and Pyschedlic Background Textures</a></li>
+ <li><a href="http://www.sxc.hu/photo/931435" title="Trainers Image">Trainers Image</a></li>
+ <li><a href="http://www.sxc.hu/photo/1015485" title="Basketball Image">Basketball Image</a></li>
+ <li><a href="http://www.sxc.hu/photo/563767" title="Bottles Image">Bottles Image</a></li>
+ </ul>
+
+ </div> <!--.story-->
+ </div> <!--#fifth-->
+</body>
+</html>
9 readme.txt
@@ -0,0 +1,9 @@
+Plugin: jQuery Parallax
+Version 1.1
+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
9 scripts/jquery.localscroll-1.2.7-min.js
@@ -0,0 +1,9 @@
+/**
+ * jQuery.LocalScroll - Animated scrolling navigation, using anchors.
+ * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
+ * Dual licensed under MIT and GPL.
+ * Date: 3/11/2009
+ * @author Ariel Flesler
+ * @version 1.2.7
+ **/
+;(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=$('<a> </a>').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);
84 scripts/jquery.parallax-1.1.js
@@ -0,0 +1,84 @@
+/*
+Plugin: jQuery Parallax
+Version 1.1
+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 that places the navigation in the center of the window
+function RepositionNav(){
+ var windowHeight = $(window).height(); //get the height of the window
+ var navHeight = $('#nav').height() / 2;
+ var windowCenter = (windowHeight / 2);
+ var newtop = windowCenter - navHeight;
+ $('#nav').css({"top": newtop}); //set the new top position of the navigation list
+}
+
+
+(function( $ ){
+ $.fn.moveRelative = function(xpos, adjuster, inertia, outerHeight) {
+
+function inView(pos, element){
+
+ element.each(function(){ //for each selector, determine whether it's inview and run the move() function
+
+ var element = $(this);
+ var top = element.offset().top;
+
+ if(outerHeight == true){
+ var height = element.outerHeight(true);
+ }else{
+ var height = element.height();
+ }
+
+ //above & in view
+ if(top + height >= pos && top + height - windowHeight < pos){
+ move(pos, height);
+ }
+
+ //full view
+ if(top <= pos && (top + height) >= pos && (top - windowHeight) < pos && top + height - windowHeight > pos){
+ move(pos, height);
+ }
+
+ //below & in view
+ if(top + height > pos && top - windowHeight < pos && top > pos){
+ move(pos, height);
+ }
+ });
+}
+
+ var $window = $(window);
+ var windowHeight = $(window).height();
+ var pos = $window.scrollTop(); //position of the scrollbar
+ var $this = $(this);
+
+ //setup defaults if arguments aren't specified
+ if(xpos == null){xpos = "50%"}
+ if(adjuster == null){adjuster = 0}
+ if(inertia == null){inertia = 0.1}
+ if(outerHeight == null){outerHeight = true}
+
+ height = $this.height();
+ $this.css({'backgroundPosition': newPos(xpos, outerHeight, adjuster, inertia)});
+
+ function newPos(xpos, windowHeight, pos, adjuster, inertia){
+ return xpos + Math.round((-((windowHeight + pos) - adjuster) * inertia)) + "px";
+ }
+
+ //function to be called whenever the window is scrolled or resized
+ function move(pos, height){
+ $this.css({'backgroundPosition': newPos(xpos, height, pos, adjuster, inertia)});
+ }
+
+ $window.bind('scroll', function(){ //when the user is scrolling...
+ var pos = $window.scrollTop(); //position of the scrollbar
+ inView(pos, $this);
+ })
+ }
+})( jQuery );
11 scripts/jquery.scrollTo-1.4.2-min.js
@@ -0,0 +1,11 @@
+/**
+ * jQuery.ScrollTo - Easy element scrolling using jQuery.
+ * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
+ * Dual licensed under MIT and GPL.
+ * Date: 5/25/2009
+ * @author Ariel Flesler
+ * @version 1.4.2
+ *
+ * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
+ */
+;(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);
136 style.css
@@ -0,0 +1,136 @@
+/*
+Plugin: jQuery Parallax
+Version 1.1
+Author: Ian Lunn
+Author URL: http://www.ianlunn.co.uk/
+Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/
+
+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/.
+*/
+
+@charset "utf-8";
+/* CSS Document */
+
+body{
+ margin: 0;
+ min-width: 980px;
+ padding: 0;
+}
+
+p{
+ margin: 0 0 20px 0;
+}
+
+p, ul{
+ font-family:"Proxima Nova Light", 'Helvetica Neue', Arial, Helvetica, sans-serif;
+ font-size-adjust:0.488;
+ font-weight:200;
+ font-style:normal;
+}
+
+img{
+ border: 0;
+}
+
+h1, #pixels{
+ font-family:"Museo 900", Verdana, serif;
+ font-size-adjust:0.40;
+ font-weight:700;
+ font-style:normal;
+}
+
+h2{
+ font-family:"Beau Sans Pro Book", Verdana, sans-serif;
+ font-size-adjust:0.531;
+ font-weight:500;
+ font-style:normal;
+}
+
+#header h1, #pixels{
+ color: #48941A;
+}
+
+.float-left{
+ float: left;
+ margin: 0 0 0 20px;
+}
+
+.float-right{
+ float: right;
+ margin: 0 20px 0 0;
+}
+
+.center{
+ font-size: 2.5em;
+ padding: 80px 0;
+ text-align: center;
+}
+
+#nav{
+ list-style: none;
+ position: fixed;
+ right: 20px;
+}
+
+#nav li{
+ margin: 0 0 15px 0;
+}
+
+#header, #intro, #second{
+ width: 100%;
+}
+
+#intro{
+ background:url(images/firstBG.jpg) 50% -75px no-repeat fixed;
+ color: white;
+ height: 600px;
+ margin: 0 auto;
+ padding: 160px 0 0 0;
+}
+
+#second{
+ background: url(images/secondBG.jpg) 50% 0 no-repeat fixed;
+ color: white;
+ height: 1300px;
+ margin: 0 auto;
+ overflow: hidden;
+ padding: 0;
+}
+
+
+#second .bg{
+ background: url(images/trainers.png) 50% 0 no-repeat fixed;
+ height: 1000px;
+ margin: 0 auto;
+ padding: 0;
+ position: absolute;
+ width: 900px;
+ z-index: 200;
+}
+
+#third{
+ background: url(images/thirdBG.jpg) 50% 0 no-repeat fixed;
+ color: white;
+ height: 650px;
+ padding: 100px 0 0 0;
+}
+
+#fifth{
+ background: #ccc;
+ height: 400px;
+ margin: 0 auto;
+ padding: 40px 0 0 0;
+}
+
+.story{
+ margin: 0 auto;
+ min-width: 980px;
+ overflow: auto;
+ width: 980px;
+}
+
+.story .float-left, .story .float-right{
+ padding: 100px 0 0 0;
+ position: relative;
+ width: 350px;
+}

0 comments on commit 0968752

Please sign in to comment.