我需要在我的 html5 (sencha touch 2) 移动应用程序中实现倒数计时器。
目前,我使用了一个 JavaScript 函数,它通过 setInterval 函数每秒更新一次计时器,然后更新 html 内容。
function updateTimer() {
now = new Date();
kickoff = Date.parse("August 15, 2013 09:00:00");
diff = kickoff - now;
days = Math.floor( diff / (1000*60*60*24) );
hours = Math.floor( diff / (1000*60*60) );
mins = Math.floor( diff / (1000*60) );
secs = Math.floor( diff / 1000 );
dd = days;
hh = hours - days * 24;
mm = mins - hours * 60;
ss = secs - mins * 60;
Ext.getCmp('countdownText').setHtml('<span class="text"><p class="val">'+dd+'</p><p class="type_days">Days</p></span><span class="text"><p class="val">'+hh+'</p><p class="type_hours">Hours</p></span><span class="text"><p class="val">'+mm+'</p><p class="type_minutes">Minutes</p></span><span class="text"><p class="val">'+ss+'</p><p class="type_seconds">Seconds</p></span>');
setInterval('updateTimer()', 1000 ); }
我的问题是,这会对应用程序的性能产生影响吗?
html5 Web Workers会更高效吗?
有没有其他方法可以实现此功能?