开发者

Multiple countdowns on the same page

I have been using this script ( http://www.dynamicdrive.com/dynamicindex6/dhtmlcount.htm ) for countdown t开发者_StackOverflow社区o vacations. But this time i need to have 2 countdowns on ONE page. I tried having 2 different pages with one script in each and include them to the main page, but that did not work.

Anyone know how to edit it or have a script that works for this purpose? I tried editing some of the variables but I were unable to get it to work.

Thanks.


I have cooked up a simple countdown Constructor which may help you further.

function countDown(startTime, divid, the_event){
    var tdiv = document.getElementById(divid)
        ,start = parseInt(startTime.getTime(),10)
        ,the_event = the_event || startTime.toLocaleString()
        ,to;
    this.rewriteCounter = function(){
      var now = new Date().getTime()
          ,diff = Math.round((start - now)/1000);
      if (startTime > now)
      {
        tdiv.innerHTML = diff +' seconds untill ' + the_event;
      }
      else {clearInterval(to);}
    };
    this.rewriteCounter();
    to = setInterval(this.rewriteCounter,1000);
}

//usage
var count1 = new countDown(new Date('2010/12/11 10:44:59')
                           ,'counter1'
                           ,'tomorrow 10:45');
var count2 = new countDown(new Date('2010/12/25')
                           ,'counter2'
                           ,'first christmas day');

Check it out @jsfiddle

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜