JSカウントダウンコードのまとめ

11193 ワード

本論文の例は、一般的なJSカウントダウンコードをまとめたものである.皆さんの参考にしてください.具体的なまとめは以下の通りです.
第一種類:正確に秒までのjavascriptカウントダウンコード 
HTMLコード: 

   
 
 
2010 :
 
 
 
 
 
  <br> startclock()  <br> var timerID = null;  <br> var timerRunning = false;  <br> function showtime() {  <br> Today = new Date();  <br> var NowHour = Today.getHours();  <br> var NowMinute = Today.getMinutes();  <br> var NowMonth = Today.getMonth();  <br> var NowDate = Today.getDate();  <br> var NowYear = Today.getYear();  <br> var NowSecond = Today.getSeconds();  <br> if (NowYear <2000)  <br> NowYear=1900+NowYear;  <br> Today = null;  <br> Hourleft = 23 - NowHour  <br> Minuteleft = 59 - NowMinute  <br> Secondleft = 59 - NowSecond  <br> Yearleft = 2009 - NowYear  <br> Monthleft = 12 - NowMonth - 1 <br> Dateleft = 31 - NowDate  <br> if (Secondleft<0)  <br> {  <br> Secondleft=60+Secondleft;  <br> Minuteleft=Minuteleft-1;  <br> }  <br> if (Minuteleft<0)  <br> {   <br> Minuteleft=60+Minuteleft;  <br> Hourleft=Hourleft-1;  <br> }  <br> if (Hourleft<0)  <br> {  <br> Hourleft=24+Hourleft;  <br> Dateleft=Dateleft-1;  <br> }  <br> if (Dateleft<0)  <br> {  <br> Dateleft=31+Dateleft;  <br> Monthleft=Monthleft-1;  <br> }  <br> if (Monthleft<0)  <br> {  <br> Monthleft=12+Monthleft;  <br> Yearleft=Yearleft-1;  <br> }  <br> Temp=Yearleft+' , '+Monthleft+' , '+Dateleft+' , '+Hourleft+' , '+Minuteleft+' , '+Secondleft+' ' <br> document.form1.left.value=Temp;  <br> timerID = setTimeout("showtime()",1000);  <br> timerRunning = true;  <br> }  <br> var timerID = null;  <br> var timerRunning = false;  <br> function stopclock () {  <br> if(timerRunning)  <br> clearTimeout(timerID);  <br> timerRunning = false;  <br> }  <br> function startclock () {  <br> stopclock();  <br> showtime();  <br> }  <br> // -->  <br>
第二種類:○運動会 
HTMLコード: 

     
  
  <br> <!--   <br> function DigitalTime1()  <br> {   <br> var deadline= new Date("08/13/2007") //   <br> var symbol="8 13 " <br> var now = new Date()  <br> var diff = -480 - now.getTimezoneOffset() //   <br> var leave = (deadline.getTime() - now.getTime()) + diff*60000 <br> var day = Math.floor(leave / (1000 * 60 * 60 * 24))  <br> var hour = Math.floor(leave / (1000*3600)) - (day * 24)  <br> var minute = Math.floor(leave / (1000*60)) - (day * 24 *60) - (hour * 60)  <br> var second = Math.floor(leave / (1000)) - (day * 24 *60*60) - (hour * 60 * 60) - (minute*60)  <br> var deadline_2= new Date("08/13/2004") //   <br> var symbol_2="8 13 " <br> var now_2 = new Date()  <br> var diff_2 = -480 - now.getTimezoneOffset() //   <br> var leave_2 = (now_2.getTime() - deadline_2.getTime()) + diff_2*60000 <br> var day_2 = Math.floor(leave_2 / (1000 * 60 * 60 * 24))  <br> var hour_2 = Math.floor(leave_2 / (1000*3600)) - (day_2 * 24)  <br> var minute_2 = Math.floor(leave_2 / (1000*60)) - (day_2 * 24 *60) - (hour_2 * 60)  <br> var second_2 = Math.floor(leave_2 / (1000)) - (day_2 * 24 *60*60) - (hour_2 * 60 * 60) - (minute_2*60)  <br> day=day+1;  <br> day_2=day_2+1;  <br> if (day>0) //   <br> {  <br> //LiveClock1.innerHTML = " "+symbol+" "  <br> LiveClock1.innerHTML = "<font <br> setTimeout("DigitalTime1()",1000)  <br> }  <br> if (day<0) //   <br> {  <br> //LiveClock1.innerHTML = " "+symbol+" "+day+" "+hour+" "+minute+" "+second +" "  <br> LiveClock1.innerHTML = "<font <br> setTimeout("DigitalTime1()",1000)  <br> }  <br> if (day==0) //   <br> {  <br> //LiveClock1.innerHTML = " "+symbol+" "  <br> LiveClock1.innerHTML = "<font <br> setTimeout("DigitalTime1()",1000)  <br> }  <br>    <br> if (day<0 & day_2>19) //   <br> {  <br> //LiveClock1.innerHTML = " "+symbol+" "+day+" "+hour+" "+minute+" "+second +" "  <br> LiveClock1.innerHTML = "<font <br> setTimeout("DigitalTime1()",1000)  <br> }  <br> }  <br> // -->  <br>  
 
 
 

 
第三种:小时倒计时 

HTML代码: 


     
  <br> <!--  
  <br> var maxtime = 60*60 //    ,    ,    !  
  <br> function CountDown(){  
  <br> if(maxtime>=0){  
  <br> minutes = Math.floor(maxtime/60);  
  <br> seconds = Math.floor(maxtime`);  
  <br> msg = "      "+minutes+" "+seconds+" ";  
  <br> document.all["timer"].innerHTML=msg;  
  <br> if(maxtime == 5*60) alert('  ,  5  !');  
  <br> --maxtime;  
  <br> }  
  <br> else{  
  <br> clearInterval(timer);  
  <br> alert("   ,  !");  
  <br> }  
  <br> }  
  <br> timer = setInterval("CountDown()",1000);  
  <br> //-->  
  <br>   
  

第四种:最简倒计时 

HTML代码: 


      
  <br> <!-- Begin   
  <br>   var timedate= new Date("January 14,2006");   
  <br>   var times="     ";   
  <br>   var now = new Date();   
  <br>   var date = timedate.getTime() - now.getTime();   
  <br>   var time = Math.floor(date / (1000 * 60 * 60 * 24));   
  <br>   if (time >= 0) ;  
  <br> document.write("<li><font color=#DEDBDE>   2006 "+times+"  : <font color=#ffffff><b>"+time +"</b></font>  </font></li>");  
  <br> // End -->  
  <br>  
 
第五種類:最速カウントダウン2 
HTMLコード: 

     
  <br> function djs(){  
  <br> var urodz= new Date("11/12/2008");   
  <br> var now = new Date();  
  <br> var num  
  <br> var ile = urodz.getTime() - now.getTime();    
  <br> var dni = Math.floor(ile / (1000 * 60 * 60 * 24));    
  <br> if (dni >1)    
  <br> num=dni+1 
  <br> else if (dni == 1) num=2   
  <br> else if (dni == 0) num=1 
  <br> else num=0   
  <br> document.write(num)    
  <br> }  
  <br>   
  
[djs()]
第六個:Javascriptカウントダウン-システム時間自己チェックを採用する
今回はシステム時間を使ってカウントダウンをチェックします.手作業で校正する必要がないので、カウントダウンがより正確になります.コードと詳細な注釈は以下の通りです. 

   00:01:11:00  
  
 
 

 
 
 
  <br> var normalelapse = 100;  <br> var nextelapse = normalelapse;  <br> var counter;   <br> var startTime;  <br> var start = clock.innerText;   <br> var finish = "00:00:00:00";  <br> var timer = null;  <br> //   <br> function run() {  <br> startB.disabled = true;  <br> endB.disabled = false;  <br> counter = 0;  <br> //   <br> startTime = new Date().valueOf();  <br> // nextelapse , 100   <br> // setInterval : nextelapse( ) , onTimer   <br> timer = window.setInterval("onTimer()", nextelapse);   <br> }  <br> //   <br> function stop() {  <br> startB.disabled = false;  <br> endB.disabled = true;  <br> window.clearTimeout(timer);  <br> }  <br> window.onload = function() {  <br> endB.disabled = true;  <br> }  <br> //   <br> function onTimer()  <br> {  <br> if (start == finish)  <br> {  <br> window.clearInterval(timer);  <br> alert("time is up!");  <br> return;  <br> }  <br> var hms = new String(start).split(":");  <br> var ms = new Number(hms[3]);  <br> var s = new Number(hms[2]);  <br> var m = new Number(hms[1]);  <br> var h = new Number(hms[0]);  <br> ms -= 10;  <br> if (ms < 0)  <br> {  <br> ms = 90;  <br> s -= 1;  <br> if (s < 0)  <br> {  <br>     s = 59;  <br>     m -= 1;  <br> }  <br> if (m < 0)  <br> {  <br>     m = 59;  <br>     h -= 1;  <br> }  <br> }  <br> var ms = ms < 10 ? ("0" + ms) : ms;  <br> var ss = s < 10 ? ("0" + s) : s;  <br> var sm = m < 10 ? ("0" + m) : m;  <br> var sh = h < 10 ? ("0" + h) : h;  <br> start = sh + ":" + sm + ":" + ss + ":" + ms;  <br> clock.innerText = start;  <br> //   <br> window.clearInterval(timer);  <br> // , nextelapse  <br> counter++;   <br> var counterSecs = counter * 100;  <br> var elapseSecs = new Date().valueOf() - startTime;  <br> var diffSecs = counterSecs - elapseSecs;  <br> nextelapse = normalelapse + diffSecs;  <br> diff.value = counterSecs + "-" + elapseSecs + "=" + diffSecs;  <br> next.value = "nextelapse = " + nextelapse;  <br> if (nextelapse < 0) nextelapse = 0;  <br> //   <br> timer = window.setInterval("onTimer()", nextelapse);   <br> }  <br>
本論文で述べたいのですが、javascriptに基づくウェブプログラムの設計に役に立つと思います.