Pregunta

He estado usando este script ( http://www.dynamicdrive.com/dynamicindex6/dhtmlcount .htm ) para la cuenta atrás para las vacaciones. Pero esta vez tengo que tener 2 cuentas atrás en una página. He intentado tener 2 páginas diferentes con un script en cada uno y los incluyo a la página principal, pero que no funcionó.

Alguien sabe cómo editarlo o tener un script que funcione para este propósito? He intentado editando algunas de las variables pero no fueron capaces de conseguir que funcione.

Gracias.

¿Fue útil?

Solución

he cocinado un simple cuenta atrás Constructor que pueden ayudarle.

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top