1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

スマホサイトでピンチアウトによる拡大をさせたくない時にやること

Posted at

まずはJavaScriptで書いてみた

(".hoge").addEventListener("touchstart", function(event) {
    if (event.touches.length > 1) {
        event.preventDefault();
    }
}, {passive: false});
  • ここでのポイント
  • event.touches.lengthにタッチ中の指の本数が格納されている
  • event.preventDefault();で拡大をキャンセルしている
  • {passive: false}をつけないとpreventDefault()が効かない

ここで問題が発生

指一本でスクロールしながらもう一本指を増やすとピンチアウトが有効になる

解決策

.hoge {
    touch-action: pan-y;
}

CSSにこれを指定するだけで実は済む。
touch-action

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?