Often in our web pages need a countdown to trigger some functions, such as masks, in this project, by using jquery,bootstrap, to achieve the display system current time, and the implementation of the Countdown function, the countdown will pop up the modal box (mask layer). The modal frame interface is friendly and flexible, appearing as a pop-up dialog box. See 1 for Details:
Project source file Address: Https://github.com/zhangxy1035/Countdown
Reference: http://v3.bootcss.com/javascript/#modals
Figure 1:
About the countdown function is as Follows:
1 varTime = 10*1000;//calculate the number of milliseconds2 varse;3SE = setinterval (' t_time () ', 1000);4 functiont_time () {5 //Countdown6 varMM = parseint (time/60/1000%60,10);//number of minutes left7 varSS = parseint (time/1000%60,10);//number of seconds remaining8MM =checktime (mm);9SS =checktime (ss);Ten$ ("#timer"). HTML (mm+ ' +ss+ ' seconds '); oneTime = time-1000; a if(mm==0 && ss==0) { -$ ("#myEnd"). Modal ("toggle")); - clearinterval (se); the } - } - - functionchecktime (i) { + if(i<10) { -i = "0" +i; + } a returni; at}
In the above code, the Checktime function, the main function is to control the display, for example, the distance time to the end of 8 seconds, the system will be displayed as 08.
Code references in Html:
1 <span class= "label badge-success" > Current time: <span id= "current-time" ></span></span>
The Modal box (mask layer) code is:
1 div id= "myend" class= "modal hide" > 2 <div class= "modal-header" > 3 < Button data-dismiss= "modal" class= "close" type= "button" >x</button> 4 5 </div> 6 <div class= "modal-body" > 7 <p> You have run out of time </p> 8 </div> 9 <div class= "modal-footer" > <a data-dismiss= "modal" class= "btn btn-success" href= "#" > OK </a> </div> </div>
After the modal box appears, you can jump to the page you're linking To.
Show current system time:
1 // Show Current Time 2 SetInterval (function() {3 var now = (new Date ()). toLocaleString (); 4 $ (' #current-time '). text (now); 5 }, 1000);
Use JS to display the current time of the system and implement the Countdown function and trigger the modal box (mask) function