-
-
Save russgossett/4686520 to your computer and use it in GitHub Desktop.
Parallax Scrolling technique
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
<body> | |
<ul id="nav"> | |
<li><a href="#intro" title="Next Section"><img src="http://placekitten.com/50/50" /></a></li> | |
<li><a href="#second" title="Next Section"><img src="http://placekitten.com/50/50" /></a></li> | |
<li><a href="#third" title="Next Section"><img src="http://placekitten.com/50/50" /></a></li> | |
<li><a href="#fifth" title="Next Section"><img src="http://placekitten.com/50/50" /></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>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>Credits</h2> | |
<p>This plugin makes use of some scripts and images made by others:</p> | |
<ul> | |
<li>item1</li> | |
<li>item2</li> | |
<li>item3</li> | |
<li>item4</li> | |
</ul> | |
</div> <!--.story--> | |
</div> <!--#fifth--> | |
</body> |
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
$(document).ready(function(){ | |
$('#nav').localScroll(800); | |
//.parallax(xPosition, speedFactor, outerHeight) options: | |
//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); | |
$('.bg').parallax("50%", 0.4); | |
$('#third').parallax("50%", 0.3); | |
}) |
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
/* | |
Plugin: jQuery Parallax | |
Version 1.1.3 | |
Author: Ian Lunn | |
Twitter: @IanLunn | |
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 0 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{ | |
margin-top: 30px; | |
background:url(http://placekitten.com/g/1800/1000) 50% 0 no-repeat fixed; | |
color: white; | |
height: 1010px; | |
margin: 0 auto; | |
padding: 0; | |
} | |
#second{ | |
background: url(http://placekitten.com/g/1750/801) 50% 0 no-repeat fixed; | |
color: white; | |
height: 700px; | |
margin: 0 auto; | |
overflow: hidden; | |
padding: 0; | |
} | |
#second .bg{ | |
/* background: url(http://placekitten.com/1000/701) 50% 0 no-repeat fixed;*/ | |
height: 1300px; | |
margin: 0 auto; | |
padding: 0; | |
position: absolute; | |
width: 900px; | |
z-index: 200; | |
} | |
#third{ | |
background: url(http://placekitten.com/g/1700/704) 50% 0 no-repeat fixed; | |
color: white; | |
height: 750px; | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parallax Scrolling technique