2
5

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 1 year has passed since last update.

JavaScriptでスクリーンロック(操作不可に)させる

Posted at

使用用途

何かしらの処理をしている間、画面操作をしてほしくない場合に使う。
処理開始時にスクリーンロックさせて、終了時に解除するという使い方。

スクリーンロックさせる

画面いっぱいのdiv要素を作ってクリック&タッチできなくする。

function screen_lock(){
  let lock_screen = document.createElement('div');
  lock_screen.id = "screenLock";

  lock_screen.style.height = '100%';
  lock_screen.style.left = '0px';
  lock_screen.style.position = 'fixed';
  lock_screen.style.top = '0px';
  lock_screen.style.width = '100%';
  lock_screen.style.zIndex = '9999';
  lock_screen.style.opacity = '0';

  let objBody = document.getElementsByTagName("body").item(0);
  objBody.appendChild(lock_screen);
}

スクリーンロックを解除する

画面いっぱいのdiv要素を消せば解除される。

function screen_unlock(){
  let screenLock = document.getElementById("screenLock");
  screenLock.parentNode.removeChild(screenLock);
}
2
5
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?