Authored by 陈轩

修复秒杀倒计时 切到后台时暂时的问题

@@ -238,27 +238,31 @@ seckillObj = { @@ -238,27 +238,31 @@ seckillObj = {
238 time = $(elem).find('input.date').val() / 1000; 238 time = $(elem).find('input.date').val() / 1000;
239 } 239 }
240 offsetTime = time - nowTime; 240 offsetTime = time - nowTime;
241 - that.startTick(elem, offsetTime); 241 + that.startTick(elem, offsetTime, nowTime);
242 }, 242 },
243 243
244 /** 244 /**
245 * [开始倒计时] 245 * [开始倒计时]
246 */ 246 */
247 - startTick: function(elem, offsetTime) { 247 + startTick: function(elem, offsetTime, nowTime) {
248 var that = this, 248 var that = this,
249 $el = this.el, 249 $el = this.el,
250 hour = parseInt(offsetTime / (60 * 60), 10), 250 hour = parseInt(offsetTime / (60 * 60), 10),
251 minute = parseInt(offsetTime % (60 * 60) / 60, 10), 251 minute = parseInt(offsetTime % (60 * 60) / 60, 10),
252 second = offsetTime % 60; 252 second = offsetTime % 60;
253 253
254 - $(elem).find('.tick.hour').text(hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : hour));  
255 - $(elem).find('.tick.minute').text(minute < 0 ? '00' : (minute < 10 ? ('0' + minute) : minute));  
256 - $(elem).find('.tick.second').text(second < 0 ? '00' : (second < 10 ? ('0' + second) : second));  
257 if (offsetTime <= 0) { // 结束倒计时刷新状态 254 if (offsetTime <= 0) { // 结束倒计时刷新状态
258 that.refreshList(elem); 255 that.refreshList(elem);
259 } else { 256 } else {
  257 + $(elem).find('.tick.hour').text(hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : hour));
  258 + $(elem).find('.tick.minute').text(minute < 0 ? '00' : (minute < 10 ? ('0' + minute) : minute));
  259 + $(elem).find('.tick.second').text(second < 0 ? '00' : (second < 10 ? ('0' + second) : second));
  260 +
260 $el.currentTick = setTimeout(function() { 261 $el.currentTick = setTimeout(function() {
261 - that.startTick(elem, --offsetTime); 262 + var curSec = Math.floor(Date.now() / 1000);
  263 +
  264 + offsetTime = offsetTime - (curSec - nowTime);
  265 + that.startTick(elem, offsetTime, curSec);
262 }, 1000); 266 }, 1000);
263 } 267 }
264 }, 268 },