LoginSignup
1
1

More than 5 years have passed since last update.

Fx0でVibration API

Posted at

WebAPIFx0での動作確認。

Vibration API

navigator.vibrate(1000);

1000ミリ秒振動させる。

navigator.vibrate([50, 100, 150]);

50ミリ秒振動させて100ミリ秒止めて150ミリ秒振動させる。

navigator.vibrate(0);

振動をすべて止める。

Fx0で動作確認

Firefox WebIDEのHello Worldテンプレで確認してみます。

app.js
window.addEventListener("load", function() {
  navigator.vibrate(1000);
});

と修正してFx0にインストールするとブーンと1秒間振動。

app.js
window.addEventListener("load", function() {
  navigator.vibrate([50, 100, 150]);
});

と修正してFx0にインストールするとブブンと振動。

app.js
window.addEventListener("load", function() {
  navigator.vibrate(-1);
});

と修正してFx0にインストールするとずっと振動しつづける。
そもそも渡す値はunsigned longとされているので-1を渡すと0xffffffffとなるのかな?

app.js
window.addEventListener("load", function() {
  document.addEventListener("touchstart", function(){
    navigator.vibrate(-1);
  });

  document.addEventListener("touchend", function(){
    navigator.vibrate(0);
  });
});

とするとタッチした間だけ振動する。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1