|
1 |
| -parallax |
2 |
| -======== |
| 1 | +# Parallax.js |
3 | 2 |
|
4 |
| -Simple, lightweight parallax engine that reacts to the orientation of a smart device |
| 3 | +Simple, lightweight **Parallax Engine** that reacts to the **orientation** of a |
| 4 | +smart device. Where no gyroscope or motion detection hardware is available, the |
| 5 | +position of the cursor is used instead. |
| 6 | + |
| 7 | +Check out this [demo][demo] to see it in action! |
| 8 | + |
| 9 | +## Setup |
| 10 | + |
| 11 | +Simply create a list of elements giving each item that you want to move within |
| 12 | +your parallax scene a class of `layer` and a `data-depth` attribute specifying |
| 13 | +its depth within the scene. A depth of **0** will cause the layer to remain |
| 14 | +stationary, and a depth of **1** will cause the layer to move by the total |
| 15 | +effect of the calculated motion. Values inbetween **0** and **1** will cause the |
| 16 | +layer to move by a reduced amount relative to its depth. |
| 17 | + |
| 18 | +```html |
| 19 | +<ul id="scene"> |
| 20 | + <li class="layer" data-depth="0.00"><img src="graphics/layer6.png"></li> |
| 21 | + <li class="layer" data-depth="0.20"><img src="graphics/layer5.png"></li> |
| 22 | + <li class="layer" data-depth="0.40"><img src="graphics/layer4.png"></li> |
| 23 | + <li class="layer" data-depth="0.60"><img src="graphics/layer3.png"></li> |
| 24 | + <li class="layer" data-depth="0.80"><img src="graphics/layer2.png"></li> |
| 25 | + <li class="layer" data-depth="1.00"><img src="graphics/layer1.png"></li> |
| 26 | +</ul> |
| 27 | +``` |
| 28 | + |
| 29 | +To start a **Parallax** scene, simply select you parent DOM Element and pass it |
| 30 | +to the **Parallax** constructor. |
| 31 | + |
| 32 | +```javascript |
| 33 | +var scene = document.getElementById('scene'); |
| 34 | +var parallax = new Parallax(scene); |
| 35 | +``` |
| 36 | + |
| 37 | +## Behaviors |
| 38 | + |
| 39 | +There are a number of behaviors that you can setup for any given **Parallax** |
| 40 | +instance. These behaviors can either be specified in the markup via data |
| 41 | +attributes or in JavaScript via the constructor or API. |
| 42 | + |
| 43 | +### Behaviors: Data Attributes |
| 44 | + |
| 45 | +```html |
| 46 | +<ul id="scene" |
| 47 | + data-easing="false" |
| 48 | + data-invert-x="false" |
| 49 | + data-invert-y="true" |
| 50 | + data-limit-x="false" |
| 51 | + data-limit-y="10" |
| 52 | + data-scalar-x="2" |
| 53 | + data-scalar-y="8"> |
| 54 | + <li class="layer" data-depth="0.00"><img src="graphics/layer6.png"></li> |
| 55 | + <li class="layer" data-depth="0.20"><img src="graphics/layer5.png"></li> |
| 56 | + <li class="layer" data-depth="0.40"><img src="graphics/layer4.png"></li> |
| 57 | + <li class="layer" data-depth="0.60"><img src="graphics/layer3.png"></li> |
| 58 | + <li class="layer" data-depth="0.80"><img src="graphics/layer2.png"></li> |
| 59 | + <li class="layer" data-depth="1.00"><img src="graphics/layer1.png"></li> |
| 60 | +</ul> |
| 61 | +``` |
| 62 | + |
| 63 | +### Behaviors: Constructor Object |
| 64 | + |
| 65 | +```javascript |
| 66 | +var scene = document.getElementById('scene'); |
| 67 | +var parallax = new Parallax(scene, { |
| 68 | + invertX: false, |
| 69 | + invertY: true, |
| 70 | + limitX: false, |
| 71 | + limitY: 10, |
| 72 | + scalarX: 2, |
| 73 | + scalarY: 8 |
| 74 | +}); |
| 75 | +``` |
| 76 | + |
| 77 | +### API |
| 78 | + |
| 79 | +```javascript |
| 80 | +var scene = document.getElementById('scene'); |
| 81 | +var parallax = new Parallax(scene); |
| 82 | +parallax.enable(); |
| 83 | +parallax.disable(); |
| 84 | +parallax.invert(false, true); |
| 85 | +parallax.limit(false, 10); |
| 86 | +parallax.scalar(2, 8); |
| 87 | +``` |
| 88 | + |
| 89 | +### jQuery |
| 90 | + |
| 91 | +```javascript |
| 92 | +$('.scene').parallax(); |
| 93 | +``` |
| 94 | + |
| 95 | +### jQuery: Passing Options |
| 96 | + |
| 97 | +```javascript |
| 98 | +$('.scene').parallax({ |
| 99 | + invertX: false, |
| 100 | + invertY: true, |
| 101 | + limitX: false, |
| 102 | + limitY: 10, |
| 103 | + scalarX: 2, |
| 104 | + scalarY: 8 |
| 105 | +}); |
| 106 | +``` |
| 107 | +### jQuery: API |
| 108 | + |
| 109 | +```javascript |
| 110 | +var $scene = $('.scene').parallax(); |
| 111 | +$scene.parallax('enable'); |
| 112 | +$scene.parallax('disable'); |
| 113 | +$scene.parallax('invert', false, true); |
| 114 | +$scene.parallax('limit', false, 10); |
| 115 | +$scene.parallax('scalar', 2, 8); |
| 116 | +``` |
| 117 | + |
| 118 | +## Author |
| 119 | + |
| 120 | +Matthew Wagerfield: [@mwagerfield][mwagerfield] |
| 121 | + |
| 122 | +## License |
| 123 | + |
| 124 | +Licensed under [MIT][mit]. Enjoy. |
| 125 | + |
| 126 | +[demo]: http://wagerfield.github.com/parallax/ |
| 127 | +[mwagerfield]: http://twitter.com/mwagerfield |
| 128 | +[mit]: http://www.opensource.org/licenses/mit-license.php |
0 commit comments