<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">
#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;

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

function on() {
    document.getElementById("overlay").style.display = "block";

function off() {
    document.getElementById("overlay").style.display = "none";
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.