Hello! I have been struggling with this modal for almost a week, trying different tutorials but nothing is helping me. I want to be able to click on an image and have a modal with a video show up. I don’t understand why it doesn’t open the modal when I click the image, and right now the modal isn’t even showing up when I disable the display: none; on the modal’s main div.
However, when I insert my code on codepen it kind of works.
relevant part of the code:
<!DOCTYPE html>
<html >
<head>
<title>Document</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#filme {
width: 80%;
display: flex;
justify-content: center;
align-items: center;
margin-top: 324px;
}
.not10 {
transform: translate(24px, -316px);
}
.bol6 {
transform: translate(-424px, 86px);
position: absolute;
}
.bol7 {
transform: translate(-486px, 412px);
position: absolute;
}
.bol8 {
transform: translate(368px, 546px);
position: absolute;
}
.not11 {
transform: translate(464px, 298px);
position: absolute;
}
#exFilme {
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
/* margin-top: 400px; */
}
#XFilme {
display: flex;
flex-direction: column;
justify-content: center
}
.esconderX {
font-size: 288px;
font-weight: 700;
color: var(--roxo);
z-index: -1;
position: absolute;
transform: translate(568px, -148px);
}
#button {
width: 648px;
height: 342px;
/*background-image: url(imagens/8emeio.png);
background-size: cover; */
cursor: pointer;
}
#text3 {
width: 348px;
display: flex;
flex-direction: column;
}
#tit1 {
margin-bottom: 0px;
}
.titulo {
font-size: 50px;
}
.bg-modal {
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
position: absolute;
/* top: 0; */
display: flex;
justify-content: center;
align-items: center;
display: none;
}
.modal-content {
/* width: 50%; */
height: 80%;
background-color: white;
border-radius: 4px;
display: flex;
justify-content: center;
align-items: center;
padding: 36px;
box-sizing: border-box;
position: relative;
}
.close {
position: absolute;
top: 6px;
right: 12px;
font-size: 28px;
font-weight: 700;
color: var(--roxo);
cursor: pointer;
}
.video {
height: 100%;
}
</style>
<script>
document.getElementById('button').addEventListener('click', function() {
document.querySelector('.bg-modal').style.display = 'flex';
});
document.querySelector('.close').addEventListener('click',function(){
document.querySelector('.bg-modal').style.display = 'none';
});
</script>
</head>
<body>
<section id="filme">
<img src="imagens/not9.png" class="not10">
<img src="imagens/bolas6.png" class="bol6">
<div id="exFilme">
<div id="XFilme">
<div class="esconderX"><p>X</p></div>
<a id="button" class="button">
<img width="648px" src="imagens/8emeio.png">
</a>
</div>
<div id="text3">
<p id="tit1" class="titulo">Excerto do filme</p>
<p>Pequena introdução ...</p>
</div>
</div>
<img src="imagens/not10.png" class="not11">
<img src="imagens/bolas7.png" class="bol7">
<img src="imagens/bolas8.png" class="bol8">
<div class="bg-modal">
<div class="modal-content">
<div class="close">X</div>
<video class="video">
<source src="videos/excertofilme.mp4" >
<source src="videos/excertofilme_1.ogv" >
</video>
</div>
</div>
</section>
</body>
</html>
I truly don’t get what is happening, specially since I am quite new to javascript, it would be awesome if you could help me!
Thank you!