I have a webpage with a lot of buttons on it and I've made a custom popup that should popup in the center of the screen when a button is clicked. Ideally the screen darkens when the window comes up and you can click off anywhere on the screen to make the window go away.
How is this done? Below is a snippet of my buttons + the popup I'd like to display when a button is pressed. The CSS window has display:hidden at the moment however.
var containerDiv = document.querySelector("#main");
let tempCounterBtn = 0;
for (let i = 0; i < 2; i++) {
let newDiv = document.createElement("div");
newDiv.id = "div-" + (i + 1);
containerDiv.appendChild(newDiv);
for (let x = 0; x < 6; x++) {
let btn = document.createElement("button");
btn.id = "button-" + (tempCounterBtn + 1);
tempCounterBtn++;
newDiv.appendChild(btn);
}
}
body {
display: flex;
justify-content: center;
margin: 1.2em;
}
button {
background: rgba(0, 0, 0, 0);
color: #a5afaa;
border: 1px solid white;
border-radius: .6em;
padding: 3em;
}
button:hover {
border-color: #fff8cc;
box-shadow: 0em 0em 1em 0em yellow;
}
#main {
border: solid 2px #939388;
border-radius: 10px;
background-color: #0f0f3de8;
box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
}
.inner {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
padding: 20px;
}
.smallFrame {
display: none;
border: solid 2px #939388;
border-radius: 10px;
background-color: #0f0f3de8;
box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
width: 400px;
height: 250px;
}
<div id="main">
<div id="inner-15" class="inner"></div>
</div>
<div class="smallFrame"></div>