index.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="initial-scale=1.0, width=device-width, user-scalable=no" />
  6. <meta name="apple-mobile-web-app-capable" content="yes" />
  7. <title>Shake.js</title>
  8. <style type="text/css">
  9. body {
  10. background: #E9E9E9;
  11. color: #333;
  12. font: 1em/1.3em "Helvetica Neue", Helvetica, Arial, Verdana, sans-serif; /* 16px / 21px */
  13. text-shadow: rgba(255,255,255,0.8) 0 1px 0;
  14. text-align: center;
  15. }
  16. </style>
  17. <script type="text/javascript" src="shake.js"></script>
  18. </head>
  19. <body>
  20. <h1>Shake to Undo</h1>
  21. <h2>for your mobile web app</h2>
  22. <p>Shake your iPhone/iPad to see a custom action.</p>
  23. <p>Works on iOS +4.2.1, Android 4.0.3 (default browser), Opera Mobile (Android), BlackBerry PlayBook 2.0</p>
  24. <p><a href="http://dev.w3.org/geo/api/spec-source-orientation">W3C DeviceOrientation Event Specification</a></p>
  25. <script type="text/javascript">
  26. window.onload = function() {
  27. //create a new instance of shake.js.
  28. var myShakeEvent = new Shake({
  29. threshold: 15
  30. });
  31. // start listening to device motion
  32. myShakeEvent.start();
  33. // register a shake event
  34. window.addEventListener('shake', shakeEventDidOccur, false);
  35. //shake event callback
  36. function shakeEventDidOccur () {
  37. //put your own code here etc.
  38. alert('Shake!');
  39. }
  40. };
  41. </script>
  42. </body>
  43. </html>