0
I created a page with three div
s that direct to videos according to their title, when clicking on each of them, a modal is opened with the respective video of div
.
This is the HTML:
<body>
<section class="cards">
<div class="card" id='LyBYdYnaX0c'>
<p class="title">Game</p>
</div>
<div class="card" id='5qap5aO4i9A'>
<p class="title">Lofi</p>
</div>
<div class="card" id='_hJZEq61KeM'>
<p class="title">Camus</p>
</div>
</section>
<div class="modalOverlay">
<div class="modalOverlayContent">
<div class="modalIframe">
<iframe src='' frameborder="0"></iframe>
</div>
<div class="modalOverlayClose">
<a>
<i class="material-icons">close</i>
</a>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
The links are dynamic, as the videos are embedded from Youtube, I put the video id as the id of each card, so the control of the links is done directly by Javascript.
const cards = document.querySelectorAll('.card')
const modalOverlay = document.querySelector('.modalOverlay')
for(let card of cards){
const videoId = card.getAttribute('id')
card.addEventListener('click', function(){
modalOverlay.classList.add('active')
modalOverlay.querySelector('iframe').src = `https://www.youtube.com/embed/${videoId}`
})
}
modalOverlay.querySelector('.modalOverlayClose').addEventListener('click', function(){
modalOverlay.classList.remove('active')
modalOverlay.querySelector('iframe').src = ""
})
The structure for
that was used in Javasscript is running full-time in the browser? Or is it only executed when called? If so, the addEventListener
would be who "calls" the structure for
? Even though you’re inside it?
Follows print of the page to make it clearer:
Recommends some specific material so I can study these mechanisms?
– Pedro Medeiros
Besides reading the links that I passed, gives a researched and look book that is unanimous on the subject. As it is not something that I have studied I can not indicate anything.
– Maniero