7
8

More than 5 years have passed since last update.

bindを用いてタッチイベントを定義した際の座標取得

Last updated at Posted at 2014-08-29

iOSなどではonmousedownonmousemoveなどのマウスイベントが使えない。

代わりにontouchstartontouchmoveなどを使う必要がある。

ここでハマったのが、タッチした座標を得る際に

$('#hoge').bind('touchstart', function(e){
    var x = e.touches[0].pageX;
    var y = e.touches[0].pageY;  //touchesが無いと怒られる
});

とすると、touchesが無いと怒られる。どうやらbindを用いると上記の方法では上手くいかないようだ。
解決策として

$('#hoge').bind('touchstart', function(e){
    var x = e.originalEvent.touches[0].pageX;
    var y = e.originalEvent.touches[0].pageY;
});

とすれば良い。

7
8
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
7
8