5
6

レーザーポインターのブックマークレット

Last updated at Posted at 2023-11-25

ソースコード

以下をブックマークに登録

javascript: {
  window.addEventListener('pointermove', ev => {
    const el = document.createElement('div');
    Object.assign(el.style, {
      width : '10px',
      height : '10px',
      backgroundColor : 'red',
      borderRadius : '50%',
      position : 'fixed',
      left : `${ev.x}px`,
      top : `${ev.y}px`,
      opacity : '1',
      transition : 'opacity .3s',
    });
    document.body.appendChild(el);

    setTimeout(() => {
      el.style.opacity = '0'; 
      setTimeout(() => el.remove(), 300);
    }, 500);
  });
}

デモ

image.png

制約

Chromeでテストしたところ、ブラウザがHTMLを開いている時には機能するのですが、PDFを開いているときにはこのブックマークレットは機能しませんでした。

元々PDFをChromeでプレゼンテーションしているときにレーザーポインターを使いたかったので残念。

謝辞

@ishi720 さん、スクロールしたときの挙動のご指摘ありがとうございます。
@onjhthrw368 さん、pointermoveイベントでのご提案ありがとうございます。コードまるごと全面採用させていただきました。

5
6
5

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
5
6