You should use a div
to overlay your page content until the countdown has ended.
Append the new div to the page, and then change it's display
CSS property to none
to hide it after five seconds.
HTML
and CSS
below are just for example, they represent your own current content, obviously.
It can be done like this -
HTML Just for example's sake.
<div id="examplecontent"></div>
CSS
#examplecontent {
height: 100vh;
width: 100vw;
background-color: #000;
}
JavaScript
window.onload = Show_Countdown;
var counter = 5;
function Show_Countdown() {
var countDown_overlay = 'position:absolute;' +
'top:50%;' +
'left:50%;' +
'background-color:white;' +
'z-index:1002;' +
'overflow:auto;' +
'width:400px;' +
'text-align:center;' +
'height:400px;' +
'margin-left:-200px;' +
'margin-top:-200px';
$('body').append('<div id="overLay" style="' + countDown_overlay + '"><span id="time"></span></div>');
var timer = setInterval(function () {
document.getElementById("time").innerHTML = counter;
counter = (counter - 1);
if (counter < 0)
{
clearInterval(timer);
document.getElementById("overLay").style.display = 'none';
}
}, 1000);
}
To go a bit further, you should disable/enable your background content dependant on whether the overlay is displayed.
Working example here
div
to display countdown over the top of the page content, which can be hidden after countdown finishes. Alert cannot do what you are asking for. – piggy Apr 22 at 13:24