forked from stephband/jparallax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
328 lines (285 loc) · 19.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="author" content="" />
<meta name="description" content="" />
<title>jQuery.parallax</title>
<script>document.documentElement.className = 'js';</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
<!-- Force latest IE rendering engine & Chrome Frame -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- Make IE recognise HTML5 elements for styling -->
<!--[if lte IE 8]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<noscript>
<strong>Warning!</strong>
Your browser does not support HTML5 so some elements on this page are simulated using JScript. Unfortunately your browser has JScript disabled. Please enable it in order to display this page.
</noscript>
<![endif]-->
<!-- Disable image toolbar in IE6 -->
<!--[if lte IE 6]><meta http-equiv="imagetoolbar" content="no" /><![endif]-->
<link rel="icon" type="image/png" href="images/favicon.png" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="stylesheet" type="text/css" href="http://stephband.info/css/template.min.css" />
<link rel="stylesheet" type="text/css" href="http://stephband.info/css/template.theme.min.css" />
<link rel="stylesheet" type="text/css" href="http://stephband.github.com/css/site.layout.css" />
<link rel="stylesheet" type="text/css" href="http://stephband.github.com/css/docs.classes.css" />
<!--[if (lt IE 9)&(!IEMobile)]>
<link rel="stylesheet" href="http://stephband.info/css/template.layout.32em.css" media="all" />
<link rel="stylesheet" href="http://stephband.info/css/template.layout.48em.css" media="all" />
<![endif]-->
<!--[if lte IE 8]><link rel="stylesheet" href="http://stephband.infocss/template.ie.css" /><![endif]-->
<!--[if IE 8]><link rel="stylesheet" href="http://stephband.infocss/template.ie8.css" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" href="http://stephband.infocss/template.ie7.css" /><![endif]-->
<!--[if IE 6]><link rel="stylesheet" href="http://stephband.infocss/template.ie6.css" /><![endif]-->
<link rel="stylesheet" href="css/jquery.parallax.css" />
<style type="text/css" media="screen, projection">
.parallax-viewport {
width: 100%;
max-width: 60em;
height: 20em;
background-color: #aebcc9;
}
.diagram {
margin-top: -0.75em;
}
small {
text-transform: uppercase;
}
</style>
</head>
<body>
<header class="site_header" id="page_header">
<div class="site_wrap wrap">
<a class="logo_thumb thumb" href="http://stephband.info" title="stephband" rel="index">
<h1>stephband.info</h1>
</a>
</div>
</header>
<div class="site_wrap wrap">
<h2>jquery.parallax</h2>
<h3>Download</h3>
<pre>git clone git://github.com/stephband/jparallax.git</pre>
<ul>
<li><a href="http://github.com/stephband/jparallax">github.com/stephband/jparallax</a></li>
</ul>
<h3>Setup and teardown</h3>
<pre style="text-align:left;color:#000000; background-color:#e8ecf0; padding:0.5em 1em 0.5em 1em;"><span style="color:#003369;">jQuery</span>( <span style="color:#760f15;">'.parallax-layer'</span> ).<span style="color:#003369;">parallax</span>( options );</pre>
<pre style="text-align:left;color:#000000; background-color:#e8ecf0; padding:0.5em 1em 0.5em 1em;"><span style="color:#003369;">jQuery</span>( <span style="color:#760f15;">'.parallax-layer'</span> ).<span style="color:#003369;">unparallax</span>();</pre>
<h3>What does jquery.parallax do?</h3>
<img src="images/diagram.png" alt="Diagram of parallax layers." class="right diagram"/>
<p>jParallax turns nodes into absolutely positioned layers that move in response to the mouse. Depending on their dimensions these layers move at different rates, in a parallaxy kind of way.</p>
<p>With a bit of CSS you can either set up windows to see these layers through, or leave them free to roam about.</p>
<p>The diagram on the right illustrates what jParallax does to the html:</p>
<pre style="text-align:left;color:#000000; background-color:#e8ecf0; padding:0.5em 1em 0.5em 1em;"><span style="color:#881280;"><ul</span><span style="color:#881280;">></span>
<span style="color:#881280;"><li <span style="color:#994500;">class</span><span style="color:#881280;">=</span><span style="color:#1a1aa6;">"parallax-layer"</span>></li></span>
<span style="color:#881280;"><li <span style="color:#994500;">class</span><span style="color:#881280;">=</span><span style="color:#1a1aa6;">"parallax-layer"</span>></li></span>
<span style="color:#881280;"></ul></span></pre>
<p>and here's a demonstration with some images:</p>
<div class="parallax-viewport" id="parallax">
<!-- parallax layers -->
<div class="parallax-layer" style="width:860px; height:273px;">
<img src="images/parallax_sketch/0_sun.png" alt="" style="position:absolute; left:300px; top:-12px;"/>
</div>
<div class="parallax-layer" style="width:920px; height:274px;">
<img src="images/parallax_sketch/1_mountains.png" alt="" />
</div>
<div class="parallax-layer" style="width:1100px; height:284px;">
<img src="images/parallax_sketch/2_hill.png" alt="" style="position:absolute; top:40px; left:0;" />
</div>
<div class="parallax-layer" style="width:1360px; height:320px;">
<img src="images/parallax_sketch/3_wood.png" alt="" style="position:absolute; top:96px; left:0;"/>
</div>
<!-- Rounded corners -->
<img src="http://stephband.info/images/corner_white_tl.png" class="tl" />
<img src="http://stephband.info/images/corner_white_tr.png" class="tr" />
<img src="http://stephband.info/images/corner_white_bl.png" class="bl" />
<img src="http://stephband.info/images/corner_white_br.png" class="br" />
</div>
<h3>More demos</h3>
<ul>
<li><a href="demos/index.html">demos/index.html</a></li>
<li><a href="demos/stalkbuttons.html">demos/stalkbuttons.html</a> - multiple parallax.</li>
<li><a href="demos/remotecontrol.html">demos/remotecontrol.html</a> - parallax by remote control.</li>
<li><a href="demos/thumbnails.html">demos/thumbnails.html</a> - beautiful interactive thumbnails.</li>
<li><a href="demos/target.html">demos/target.html</a> - demonstrates how smoothly jParallax handles window resizing.</li>
</ul>
<h3>Using jquery.parallax</h3>
<p>The default behaviour of jParallax is to show the whole width of a layer in response to the mouse travelling the whole width of the mouseport. When the mouse is moved to the extreme left-hand side of the mouseport the left-hand side of the layer meets the left-hand side of its viewport, and when the mouse is moved to the extreme right-hand side of the mouseport the right-hand side of the layer arrives at the right hand-side of its viewport. In this way, bigger layers move faster.</p>
<p>The simplest way to use jParallax is to give layers different sizes in CSS. The <a href="demos/index.html">Colour Drops Demo</a> is made like this, with jParallax in its default state and the 'speed' of the layers controlled by the size of the images. Only the mouseport option is defined.</p>
<p>One problem with the default approach is that the uppermost layer is in front of the others, and any links in the layers underneath are not clickable. To solve this, jquery.parallax also accepts the options <code>width</code> and <code>height</code>. By making layers very small in CSS, but overriding those dimensions with the <code>width</code> and <code>height</code> options, it is possible to position links inside those layers and avoid the upper layers from obscuring the lower.</p>
<h3>CSS</h3>
<p>The classic style is the 'viewport' effect. To see layers through a viewport, wrap them in a container with the style:</p>
<pre style="text-align:left;color:#000000; background-color:#e8ecf0; padding:0.5em 1em 0.5em 1em;">.parallax-viewport {
<span style="color:#88134f;">position</span>:<span style="color:#9b4400;">relative</span>;
<span style="color:#88134f;">overflow</span>:<span style="color:#9b4400;">hidden</span>;
<span style="color:#88134f;">width</span>:<span style="color:#0000ff;"><em>n</em>px</span>;
<span style="color:#88134f;">height</span>:<span style="color:#0000ff;"><em>n</em>px</span>;
}</pre>
<p>The <code>position</code> declaration sets up the viewport as an offset parent for the layers, while <code>overflow:hidden;</code> stops them being visible outside its boundaries. In order for the layers to respond, they must be given:</p>
<pre style="text-align:left;color:#000000; background-color:#e8ecf0; padding:0.5em 1em 0.5em 1em;">.parallax-layer {
<span style="color:#88134f;">position</span>:<span style="color:#9b4400;">absolute</span>;
}</pre>
<p>The stylesheet included with jquery.parallax provides these classes, and the <a href="demos/index.html">demos</a> are a good reference for some other effects you can achieve.</p>
<p>We all like tweaky-tweaky. jQuery.parallax also provides options and event bindings that give you control over a layer's behaviour.</p>
<h3>Options</h3>
<table class="options">
<thead>
<tr>
<td>Option</td><td>Type</td><td>Default</td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2" class="key">mouseport</td><td class="value">selector string | jQuery object</td><td class="default">jQuery(document)</td>
</tr>
<tr>
<td colspan="2" class="note">Identifies DOM node to track the mouse in.</td>
</tr>
<tr>
<td class="key">xparallax</td><td class="value">boolean | 0-1 | '<em>n</em>%' | '<em>n</em>px'</td><td class="default">true</td>
</tr>
<tr>
<td rowspan="2" class="key">yparallax</td><td class="value">boolean | 0-1 | '<em>n</em>%' | '<em>n</em>px'</td><td class="default">true</td>
</tr>
<tr>
<td colspan="2" class="note">Set to true or false to enable or disable movement. Alternatively, to control the range over which a layer travels, either pass in an absolute value in pixels, or a scaling factor in the range 0-1 (scaling factors can also be expressed as percentage strings). Scaling factors outside this range are also accepted, but be aware that factors below 0 (or '0%') will reverse the direction of travel, and greater than 1 (or '100%') will make layer edges appear inside the extremes of the viewport.</td>
</tr>
<tr>
<td class="key">xorigin</td><td class="value">0-1 | '<em>n</em>%' | 'left', 'center', 'middle', 'right'</td><td class="default">0.5</td>
</tr>
<tr>
<td rowspan="2" class="key">yorigin</td><td class="value">0-1 | '<em>n</em>%' | 'top', 'center', 'middle'. 'bottom'</td><td class="default">0.5</td>
</tr>
<tr>
<td colspan="2" class="note">Only meaningful when xparallax or yparallax are not 1. Determines which point of the layer lines up with which point of the viewport when the mouse is at that point in the mouseport. Got that?<br /><br />It's easy really. It's the same behaviour as the css property <code>background-position</code>. If xorigin is set to <strong>0</strong> (or <strong>'left'</strong>), then when the mouse is moved to the left hand side of the mouseport the left hand side of the layer arrives at the left hand side of the viewport. If it's set to <strong>0.5</strong> (or <strong>'center'</strong>), then when the mouse is at the centre of the mouseport the centre of the layer is aligned with the centre of the viewport. And similarly with <strong>1</strong> (or <strong>'right'</strong>).<br /><br />
Numbers outside the range 0-1 may also be used.</td>
</tr>
<tr>
<td rowspan="2" class="key">freezeClass</td><td class="value">string</td><td class="default">'freeze'</td>
</tr>
<tr>
<td colspan="2" class="note">Class set on a layer when it is frozen.</td>
</tr>
<tr>
<td rowspan="2" class="key">decay</td><td class="value">0-1</td><td class="default">0.66</td>
</tr>
<tr>
<td colspan="2" class="note">Sets the rate at which the layers 'catch up' with the mouse position. 0 is instantly, 1 is forever.</td>
</tr>
<tr>
<td rowspan="2" class="key">frameDuration</td><td class="value">int (milliseconds)</td><td class="default">30</td>
</tr>
<tr>
<td colspan="2" class="note">Length of time between animation frames. With a lot of big layers, you may want to increase the frame duration to save CPU. About 50 is acceptable (20 frames/second), but I like it zippy. Modern browsers like <a href="http://www.google.com/chrome/">Google Chrome</a> have really accurate timing, but many older browsers choke below about 15ms.</td>
</tr>
<tr>
<td class="key">width</td><td class="value">int (px)</td><td class="default">undefined</td>
</tr>
<tr>
<td rowspan="2" class="key">height</td><td class="value">int (px)</td><td class="default">undefined</td>
</tr>
<tr>
<td colspan="2" class="note">Values for layer dimensions, normally read from css, can be overridden. This does NOT change the size of the layer, only jParallax's idea of how big it is. This can be very useful in cases where you want to be able to 'click through' the upper layers. Typically you make layers very small in css, but tell jParallax they are big via the width and height options.</td>
</tr>
</tbody>
</table>
<h3>Layer Options</h3>
<p>In addition to the global options above, individual layers can be passed their own set of options as extra arguments:</p>
<pre style="text-align:left;color:#000000; background-color:#e8ecf0; padding:0.5em 1em 0.5em 1em;"><span style="color:#003369;">jQuery</span>(<span style="color:#760f15;">'.parallax-layer'</span>)
.<span style="color:#003369;">parallax</span>(options, layer_0_options, layer_1_options, ... );</pre>
<p>As an example, to give the second layer a set xparallax value, but pass no options as default:</p>
<pre style="text-align:left;color:#000000; background-color:#e8ecf0; padding:0.5em 1em 0.5em 1em;"><span style="color:#003369;">jQuery</span>(<span style="color:#760f15;">'.parallax-layer'</span>)
.<span style="color:#003369;">parallax</span>({}, {}, {xparallax: <span style="color:#760f15;">'200px'</span>});</pre>
<p>A layer option object can have the properties xparallax, yparallax, xorigin, yorigin, width and height, with the same meanings as described above.</p>
<h3>Events</h3>
<p>Events can be triggered on layers using jQuery's trigger method:</p>
<pre style="text-align:left;color:#000000; background-color:#e8ecf0; padding:0.5em 1em 0.5em 1em;"><span style="color:#003369;">jQuery</span>(<span style="color:#760f15;">'.parallax-layer'</span>)
.<span style="color:#003369;">trigger</span>(<span style="color:#760f15;">'freeze'</span>);</pre>
<table class="options">
<thead>
<tr>
<td>Event</td><td>Event object</td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2" class="key">freeze</td><td class="value">{ type: 'freeze', x: <em>0-1</em>, y: <em>0-1</em>, decay: <em>0-1</em> }</td>
</tr>
<tr>
<td class="note">Stops the layer from moving. Use the optional event object properties to send the layer to a specific position: <code>x</code> and <code>y</code> tell a layer where to go (expressed as a ratio of the width of the viewport in the range 0-1), and <code>decay</code> how fast to go there ( where 0 is immediate and 1 is forever ). When the layer comes to rest the class <code>'freeze'</code> is given to the layer. freezeClass is setable in the options object. </td>
</tr>
<tr>
<td rowspan="2" class="key">unfreeze</td><td class="value">{ type: 'unfreeze' }</td>
</tr>
<tr>
<td class="note">Should be 'thaw', I suppose, really. That sounds weird, though. Unfreeze sets the layer in motion again.</td>
</tr>
</tbody>
</table>
<h3>Some sites using jParallax</h3>
<ul>
<li><a href="http://www.thebeatlesrockband.com/">The Beatles Rock Band</a></li>
<li><a href="http://neverforget.us">Never Forget Us</a></li>
<li><a href="http://www.axethebeertax.com/">I'm Backing the Pub Campaign</a></li>
<li><a href="http://www.darrylworley.com/">www.darrylworley.com</a></li>
<li><a href="http://tnvacation.com/trails/">Discover Tennesee</a></li>
<li><a href="http://www.foldifoldi.com/">foldifoldi.com</a></li>
<li><a href="http://omarelsayed.com/">omarelsayed.com</a>
<li><a href="http://htmlexpress.de/">htmlexpress.de</a></li>
<li><a href="http://http://thierrysegur.com/">thierrysegur.com</a></li>
<li><a href="http://kalendiar.cz">kalendiar.cz</a></li>
<li><a href="http://flickaway.s3.amazonaws.com/ploreex/ploreex.html">Experimental flickr visualiser</a></li>
<li><a href="http://themeforest.net/item/communizine/19178">Communizine Wordpress theme</a></li>
<li><a href="http://housamz.com">housamz.com</a></li>
</ul>
<p>Let me know if you have a site that uses jParallax - tweet me <a href="http://twitter.com/stephband">@stephband</a>.</p>
<h3>Tips</h3>
<h4>Transparent image layers</h4>
<p>Lots of transparency in images will slow down a browser's ability to render quickly. Avoid making huge layers of semi-opaque graphics if you don't want lesser browsers to choke.</p>
<h3>Version history</h3>
<p>See the <a href="changelog.html">changelog</a>.</p>
<h3>Bug reporting</h3>
<p><a href="https://github.com/stephband/jparallax/issues">github.com/stephband/jparallax/issues</a></p>
</div>
<footer class="site_footer">
<div class="full_wrap wrap">
<div class="bio_col col">
<h3>Who made this?</h3>
<p>I did. I come from Scotland and I live in Lausanne, Switzerland. I make web things at <a href="http://cruncher.ch">Cruncher</a>. I miss Branston Pickle. When I'm not glued to a screen I play music and hike mountains.</p>
</div
><div class="repo_col col">
<h3>More code</h3>
<ul class="repo_index index">
<li><a href="http://stephband.info/template">Template</a></li>
<li><a href="http://stephband.info/jparallax/">jQuery.parallax</a></li>
<li><a href="http://stephband.info/jquery.event.tap/">jQuery.event.tap</a></li>
<li><a href="http://stephband.info/jquery.event.move/">jQuery.event.move</a></li>
<li><a href="http://stephband.info/jquery.event.swipe/">jQuery.event.swipe</a></li>
</ul>
</div
><div class="social_col col">
<h3>Find me on...</h3>
<ul class="social_index index">
<li><a href="http://twitter.com/stephband">twitter</a></li>
<li><a href="http://github.com/stephband">github</a></li>
<li><a href="http://plus.google.com/114566808430966059989/photos">google+</a></li>
<li><a href="http://www.linkedin.com/profile/view?id=27013870">linkedin</a></li>
</ul>
</div>
</div>
</footer>
<!--script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script-->
<script src="js/jquery-1.7.2.js"></script>
<script src="js/jquery.parallax.js"></script>
<script>
jQuery(document).ready(function(){
jQuery('#parallax .parallax-layer')
.parallax({
mouseport: jQuery('#parallax')
});
});
</script>
</body>
</html>