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

【React】画像がクリックされたあと、一定時間その画像のクリックを不可能にする

Last updated at Posted at 2025-02-26

目的

画像(imgタグ)をクリックすると処理が走るが、連続クリックしてしまうのを防止したい

前提

imgタグにonclick属性でクリック時の処理を記載

画像クリックを無効化する

pointer-events: none;にすることで要素のクリック、ホバーなどを無効化できる

onclickで渡されたevent.targetのpointer-eventsをnoneにする。
一定時間(Setinterval)経つと、auto に戻す

event.target.style.pointerEvents = "none";
    setTimeout(function() {
      event.target.style.pointerEvents = "auto";
      console.log("クリック再開可能になりました。");
    }, 3000);

備考

画像が直接保存されたくない時などにも便利かも

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