DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> jquery 倒計時效果實現秒殺思路
jquery 倒計時效果實現秒殺思路
編輯:JQuery特效代碼     
. 代碼如下:
<script type="text/javascript">
$(function(){
countDown("2015/9/8 11:11:59","#colockbox1");
});
function countDown(time,id){
var day_elem = $(id).find('.day');
var hour_elem = $(id).find('.hour');
var minute_elem = $(id).find('.minute');
var second_elem = $(id).find('.second');

//if(typeof end_time == "string")
var end_time = new Date(time).getTime(),//月份是實際月份-1
sys_second = (end_time-new Date().getTime())/1000;
var timer = setInterval(function(){
if (sys_second > 1) {
sys_second -= 1;
var day = Math.floor((sys_second / 3600) / 24);
var hour = Math.floor((sys_second / 3600) % 24);
var minute = Math.floor((sys_second / 60) % 60);
var second = Math.floor(sys_second % 60);
day_elem && $(day_elem).text(day);//計算天
$(hour_elem).text(hour<10?"0"+hour:hour);//計算小時
$(minute_elem).text(minute<10?"0"+minute:minute);//計算分鐘
$(second_elem).text(second<10?"0"+second:second);//計算秒殺
} else {
clearInterval(timer);
}
}, 1000);
}
</script>

html:
. 代碼如下:
<div class="colockbox" id="colockbox1">
<span class="day">00</span>
<span class="hour">00</span>
<span class="minute">00</span>
<span class="second">00</span>
</div>

公司做了個秒殺頁面,需要做一個倒計時效果,特此收藏

代碼演示下載:http://www.jb51.net/jiaoben/103648.html
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved