倒计时
js代码倒计时
var time_now_server,time_now_client,time_end,time_server_client,timerID; var oDate = new Date ();var year = oDate.getFullYear(); var month = oDate.getMonth()+1 ; var day = oDate.getDate(); var hours = oDate.getHours(); var minutes = oDate.getMinutes(); var seconds = oDate.getSeconds(); console.log(year);console.log(month);console.log(day);time_now_server=new Date ();time_now_server=time_now_server.getTime(); time_now_client=new Date (); time_now_client=time_now_client.getTime(); time_server_client=time_now_server-time_now_client; function show_time (time) { var timer = document.getElementById("timer" ); if (!timer){ return ; } timer.innerHTML =time_server_client; var time_now,time_distance,str_time; var int_day,int_hour,int_minute,int_second; var time_now=new Date (); time_now=time_now.getTime()+time_server_client; time_distance=time-time_now; if (time_distance>0 ) { int_day=Math .floor(time_distance/86400000 ) time_distance-=int_day*86400000 ; int_hour=Math .floor(time_distance/3600000 ) time_distance-=int_hour*3600000 ; int_minute=Math .floor(time_distance/60000 ) time_distance-=int_minute*60000 ; int_second=Math .floor(time_distance/1000 ) if (int_hour<10 ) int_hour="0" +int_hour; if (int_minute<10 ) int_minute="0" +int_minute; if (int_second<10 ) int_second="0" +int_second; var str = '' ; str += '<span>本轮剩余时间</span>' ;str += '<span class="span-time">' +int_hour+'</span>:' ;str += '<span class="span-time">' +int_minute+'</span>:' ;str += '<span class="span-time">' +int_second+'</span>' ; timer.innerHTML=str; setTimeout("show_time(" +time+")" ,1000 ); } else { timer.innerHTML =timer.innerHTML; clearTimeout(timerID) } }
html代码:
<div class ="seckill-time" > <div id ="timer" class ="seckill-time-area" > <span > 本轮剩余时间</span > <span class ="span-time" > 00</span > :<span class ="span-time" > 00</span > :<span class ="span-time" > 00</span > </div > <span class ="seckill-next" > </span >
</div >