タッチエンド座標をキャプチャするにはどうすればいいですか? 質問する

タッチエンド座標をキャプチャするにはどうすればいいですか? 質問する

イベントでタッチ座標をキャプチャしようとしましたtouchendが、未定義になります。touchstartイベントはうまく機能しますが、同じ概念はで失敗しますtouchend。私はこのコードを と で構築しましmousedownmouseupそれうまく動作します。

何が足りないのでしょうか?

div.addEvent("touchstart", function (event) {
    event.preventDefault(); // to avoid scrolling
    span.innerHTML = event.page.x;
});
div.addEvent("touchend", function (event) {
    span.innerHTML = event.page.x;
});

フィドル

ベストアンサー1

に値を保存しtouchmove、 で読み込む必要がありますtouchend

var lastMove = null;

// Save the touchstart to always have a position
div.addEvent('touchstart', function(event) {
  lastMove = event;
});

// Override with touchmove, which is triggered only on move
div.addEvent('touchmove', function(event) {
  lastMove = event;
});

おすすめ記事