onDeviceMotion

The iPhone has an accelerometer which can help you to detect phone movements and tilts. <br/> <br/> window.ondevicemotion = funcRef; <br/> Where funcRef is a reference to a function. This function receives a DeviceMotionEvent object describing the motion that occurred. <br/> <br/> HTML5
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
window.ondevicemotion = function(coords) { 
    
    var accX = coords.acceleration.x;
    var accY = coords.acceleration.y;
    var accZ = coords.acceleration.z;
    
    // your code goes here
};
/*
* Example
*/
/*
HTML CODE:
<h3 id="shaker-title">Shake your Smartphone to switch images</h3>
<p>Wont work on all Browsers</p>
<img id="shaker-img" src="my-image-1" alt="" border="0">   */
var pos = 0;
var lastAction = new Date();
var sensibility = 3;
var minTime     = 500;
var images = [
                'my-image-1.jpg',
                'my-image-2.jpg',
                'my-image-3.jpg',
              ];
function shakeIt()
{
    
    window.ondevicemotion = function(coords) {
        var accX = coords.acceleration.x;
        
        var time = new Date();
        
        if (time-lastAction<minTime) return false;
        
        if (accX>=sensibility || accX<=-sensibility) {
X

Url: http://www.medienservice-ladewig.de/Smartphone-Beschleunigungssensor-Javascript.2099932112.html

Language: JavaScript | User: Jörg | Created: Oct 25, 2013 | Tags: javascript iphone smartphone ondevicemotion event Accelerometer html5