再看源代">
Home > Web Front-end > JS Tutorial > JavaScript implements a simple countdown pop-up window DEMO with pictures_javascript skills

JavaScript implements a simple countdown pop-up window DEMO with pictures_javascript skills

WBOY
Release: 2016-05-16 16:56:42
Original
1215 people have browsed it

I recently made a simple settings web page. Because I needed to restart the device function, I wanted to add a countdown pop-up interface to it.

The initial idea was to customize an alert pop-up window, but I soon discovered that the alert would always stay there waiting for click confirmation, rather than the automatic and continuous display effect I wanted.

Later, I thought that it would be possible to directly display and hide pop-up windows made from DIVs. Based on this idea, we have the following:

First look at the rendering:
JavaScript implements a simple countdown pop-up window DEMO with pictures_javascript skills
JavaScript implements a simple countdown pop-up window DEMO with pictures_javascript skills
Then look at the source code:

Copy code The code is as follows:






lt;script type="text/javascript">

var cancel_flag = 0;
var already = 0;

/* Operation performed as soon as the web page is loaded*/
window.onload = reboot();

/* Click operation of the restart button*/
function reboot(){
if(confirm("This operation will disconnect all current connections and restart your device. Are you sure you want to continue? ")){
document.getElementById("reboot_pre_time").innerHTML = 4;
document.getElementById("reboot_ing_time").innerHTML = 14;
document.all.progress_reboot.innerHTML = "|" ;
download_flag = 0;
cancel_flag = 0;
already = 0;
setTimeout("showDiv('reboot_pre')",500);
delayPre_reboot("reboot_pre_time");
}
}
/* Timer the restart preparation pop-up window for 5 seconds*/
function delayPre_reboot(str) {
if(!cancel_flag){
var delay = document.getElementById(str ).innerHTML;
if(delay > 0) {
delay--;
document.getElementById(str).innerHTML = delay;
setTimeout("delayPre_reboot('reboot_pre_time')", 1000);
} else {
hideDiv("reboot_pre");
setTimeout("showDiv('reboot_ing')",500);
delayDo_reboot("reboot_ing_time");
}
}
}
/* Restart pop-up window in progress for 15 seconds*/
function delayDo_reboot(str){
display_reboot(100);
var delay = document.getElementById( str).innerHTML;
if(delay > 0) {
delay--;
document.getElementById(str).innerHTML = delay;
setTimeout("delayDo_reboot('reboot_ing_time')" , 1000);
} else {
hideDiv("reboot_ing");
alert("Reboot successfully! ");
}
}
/* Event of cancel button during reboot preparation*/
function reboot_cancel(){
cancel_flag = 1;
hideDiv("reboot_pre");
alert("You have successfully canceled the restart operation!");
}
/* Show pop-up window*/
function showDiv (str){
document.getElementById(str). style.visibility = "visible";
}
/* Hide pop-up window*/
function hideDiv (str){
document.getElementById(str).style.visibility = "hidden";
}

/* Restart pop-up window timing and buffer bar movement*/
function display_reboot(max){
already;
var dispObj = document.all.progress_reboot;
dispObj.style.width = 100.0*already/max "px";
document.all.progress_reboot.innerHTML = "||||";
var timer = window.setTimeout("display( " max ")",1000);
if (already >= max){
window.clearTimeout(timer);
}
}


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template