You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+40-40
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,12 @@
1
1
# Parallax.js
2
2
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.
3
+
Parallax Engine that reacts to the orientation of a smart device. Where no gyroscope or motion detection hardware is available, the position of the cursor is used instead.
6
4
7
5
Check out this **[demo][demo]** to see it in action!
8
6
9
7
## Setup
10
8
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 an amount relative to the supplied ratio.
9
+
Create a list of elements giving each item that you want to move within your parallax scene a class of `layer` and a `data-depth` attribute specifying its depth within the scene. A depth of **0** will cause the layer to remain stationary, and a depth of **1** will cause the layer to move by the total effect of the calculated motion. Values inbetween **0** and **1** will cause the layer to move by an amount relative to the supplied ratio.
17
10
18
11
```html
19
12
<ulid="scene">
@@ -26,19 +19,38 @@ layer to move by an amount relative to the supplied ratio.
26
19
</ul>
27
20
```
28
21
29
-
To kickoff a **Parallax** scene, simply select your parent DOM Element and pass
30
-
it to the **Parallax** constructor.
22
+
To kickoff a **Parallax** scene, select your parent DOM Element and pass it to the **Parallax** constructor.
31
23
32
24
```javascript
33
25
var scene =document.getElementById('scene');
34
26
var parallax =newParallax(scene);
35
27
```
36
28
29
+
## Understanding Layer Motion Calculations
30
+
31
+
The amount of motion that each layer moves by depends on 3 contributing factors:
32
+
33
+
1. The `scalarX` and `scalarY` values (see [Behaviours](#behaviours) below for configuration)
34
+
2. The dimensions of the parent DOM element
35
+
3. The `depth` of a layer within a parallax scene (specified by it's `data-depth` attribute)
So for a layer with a `data-depth` value of `0.5` within a scene that has both the `scalarX` and `scalarY` values set to `10` ( *the default* ) where the containing scene element is `1000px x 1000px`, the total motion of the layer in both `x` and `y` would be:
45
+
46
+
```coffeescript
47
+
xMotion=1000/10*0.5=50# 50px of positive and negative motion in x
48
+
yMotion=1000/10*0.5=50# 50px of positive and negative motion in y
49
+
```
50
+
37
51
## Behaviours
38
52
39
-
There are a number of behaviours that you can setup for any given **Parallax**
40
-
instance. These behaviours can either be specified in the markup via data
41
-
attributes or in JavaScript via the constructor and API.
53
+
There are a number of behaviours that you can setup for any given **Parallax** instance. These behaviours can either be specified in the markup via data attributes or in JavaScript via the constructor and API.
@@ -55,8 +67,7 @@ attributes or in JavaScript via the constructor and API.
55
67
|`friction-x`|`number``0 - 1`| The amount of friction the layers experience. This essentially adds some easing to the layer motion. |
56
68
|`friction-y`|`number``0 - 1`| The amount of friction the layers experience. This essentially adds some easing to the layer motion. |
57
69
58
-
In addition to the behaviours described above, there are **two** methods `enable()`
59
-
and `disable()` that *activate* and *deactivate* the **Parallax** instance respectively.
70
+
In addition to the behaviours described above, there are **two** methods `enable()` and `disable()` that *activate* and *deactivate* the **Parallax** instance respectively.
If you are writing a **native iOS application** and would like to use **parallax.js**
157
-
within a `UIWebView`, you will need to do a little bit of work to get it running.
167
+
If you are writing a **native iOS application** and would like to use **parallax.js** within a `UIWebView`, you will need to do a little bit of work to get it running.
158
168
159
-
`UIWebView` no longer automatically receives the `deviceorientation` event, so
160
-
your native application must intercept the events from the gyroscope and reroute
161
-
them to the `UIWebView`:
169
+
`UIWebView` no longer automatically receives the `deviceorientation` event, so your native application must intercept the events from the gyroscope and reroute them to the `UIWebView`:
162
170
163
-
1. Include the **CoreMotion** framework `#import <CoreMotion/CoreMotion.h>`
164
-
and create a reference to the **UIWebView**`@property(nonatomic, strong) IBOutlet UIWebView *parallaxWebView;`
165
-
2. Add a property to the app delegate (or controller that will own the **UIWebView**)
1. Include the **CoreMotion** framework `#import <CoreMotion/CoreMotion.h>` and create a reference to the **UIWebView**`@property(nonatomic, strong) IBOutlet UIWebView *parallaxWebView;`
172
+
2. Add a property to the app delegate (or controller that will own the **UIWebView**) `@property(nonatomic, strong) CMMotionManager *motionManager;`
0 commit comments