LoginSignup
1
3

More than 3 years have passed since last update.

いつも忘れる ApplePencil対応

Last updated at Posted at 2020-05-13

Apple pencilなんで仕事してくれへんの

selectやinputをApple pencilで突きすぎてペン先が磨耗した人向け

動け!(切望)

const elm = document.getElementById('idDayo')
elm.addEventListener('touchstart', function(){
  elm.focus();
  elm.select();
})

cssにcusrosr:pointer;をつけると良いなど、探すといろいろな方法があるがどれも期待した動作をしない。。。
メンテナンス性は悪いけど、期待する動作はしてくれたのでおけまる

クラスで使用する場合

class NanikaClass{
  constructor() {
    this.elm = document.getElementById('idDayo')
    this.elm.addEventListener('touchstart', function() {
      this.elem.focus();
      this.elem.select();
    }
  }  
}

thisのスコープで悩む人(メンバー呼び出し思考)は.bind(this)で我慢して。
メンテナンス性を考えると、基底クラスにイベント登録用の関数を作って、そこで処理の共通化を行う方が良さそう。

Let's タブレット対応
1
3
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
3