I have a 'start' button that triggers a modal window with an embedded video. Once the user closes the modal, I want to show a 'redeem' button after a delay of 6 seconds.
HTML:
<a id="video-start" onclick="openVideoModal()"><img src="images/playbutton.png"></a>
<div id="modal_video" class="modal">
<div class="modal-content">
<span class="close">×</span>
<iframe width="560" height="315" src="https://www.youtube.com/embed/O_GQbO7Tthg" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>
<button id="redeem" class="claim hide">Redeem</button></div>
CSS:
.modal_video {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #ffffff;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 40%;
font-family: 'Rubik', sans-serif;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.claim {
display: none;
}
.modal-content iframe{
margin: 0 auto;
display: block;
}
Javascript:
function openVideoModal() {
document.getElementById('modal_video').style.display = "block";
}
function showRedeemButton() {
var redeemBtn = document.getElementById("redeem");
if (redeemBtn.classList.contains("hide")) {
redeemBtn.classList.remove("hide");
} else {
redeemBtn.classList.add("hide");
}
}
document.querySelector(".close").onclick = function() {
document.getElementById('modal_video').style.display = "none";
setTimeout(showRedeemButton, 6000);
};
window.onclick = function(event) {
if(event.target == document.getElementById('modal_video')) {
document.getElementById('modal_video').style.display = "none";
showRedeemButton();
}
}
The functionality works until I close the video modal; the 'redeem' button does not appear.
I've attempted removing the timeout and directly calling the function, but it still doesn't show up. I'm unsure of what's causing this issue, so I'm at a loss for other solutions to try.