I’ve got the modal box appearing after 3 seconds as well as a black background set to 50% opacity. Right now the box and background just appears right at 3 seconds, I can’t quite figure out how to have the opacity go from 0% (0.0) to 50% (0.5) starting at 3 seconds.
CSS:
.modal {
display: none;
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
justify-content: center;
align-items: center;
}
JS:
const modal = document.getElementById("myModal");
const span = document.querySelector(".close");
setTimeout(function () {
modal.style.display = "flex";
}, 3000);
span.onclick = () => {
modal.style.display = "none";
};
2
Answers
Try this CSS
it will fade in opacity
Here are the bugs with your code. Your css was a class and not an ID. So, JS could not find the ID to trigger.
I changed that to the ID name as defined in your JS
Using an animation to get around the item being display none