2018年3月8日 星期四

Detect shake using javascript

Ref: http://qnimate.com/detect-shake-using-javascript/
Server (Windows 10/IIS @ ASUS X450J) iphone 5s (Chrome) zenfone 6

1. 參考REF程式
<html>
<head>
<title> Test shake</title>
<script type="text/javascript" src="https://cdn.rawgit.com/alexgibson/shake.js/master/shake.js"></script>
<script> 
    //listen to shake event
    var shakeEvent = new Shake({threshold: 15});
    shakeEvent.start();
    window.addEventListener('shake', function(){
        alert("Shaked");
    }, false);

    //stop listening
    function stopShake(){
        shakeEvent.stop();
    }

    //check if shake is supported or not.
    if(!("ondevicemotion" in window)){alert("Not Supported");}
</script>
</head>
<body>
<h1>Test shake event</h1>
</body>
2. Zenfone 6
3. iphone 5s





沒有留言:

張貼留言