LoginSignup
10

More than 5 years have passed since last update.

モーダルウィンドウの作り方 - Javascript

Last updated at Posted at 2018-01-20

on.gif

実装

コピペで動くはず

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#overlay {
    position: fixed;
    display: none;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 2;
    cursor: pointer;
}
</style>
</head>

<body>
<div id="overlay" onclick="off()"><h1>Hay</h1></div>
<button onclick="on()">Turn on overlay effect</button>

<script>
function on() {
    document.getElementById("overlay").style.display = "block";
}

function off() {
    document.getElementById("overlay").style.display = "none";
}
</script>  
</body>
</html> 

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
10