Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/07/2008, 14:56
Avatar de JoniJnm
JoniJnm
 
Fecha de Ingreso: mayo-2007
Ubicación: Madrid
Mensajes: 264
Antigüedad: 17 años
Puntos: 4
De acuerdo Nuevo contador cuenta atrás con javascript

Hola, uniendo códigos que he visto por ahí y modificándolos he hecho un reloj cuenta atrás, aquí lo tienen:

(El primer script se puede poner tantas veces como eventos se quiera, en él se pone la fecha del evento)

Código PHP:
<script type='text/javascript'>
/*
Modificado y recopilado por JoniJnm
http://www.jonijnm.es
*/

var id;
if (!
id) { id 1; }
else { 
id++; }

document.write("<table border='0' width='100%'>");
document.write("<span><b>· Nombre del evento:</b></span><br>");
document.write("<span><font color='#FF0000'><b>El evento</b></font></span><br>");
document.write("<span><b>· D&iacute;a del evento:</b></span><br>");
document.write("<span id='evento" id "'></span>");
document.write("<span><b>· Tiempo Restante:</b></span><br>");
document.write("<span id='contar" id "'></span>");
document.write("</table>");
document.write("<p><small><b><a href='http://www.jonijnm.es' style='text-decoration: none'>www.JoniJnm.es</a></b></small></p>");

//PON AQUÍ LA FECHA DEL EVENTO, ANO, MES, DIA, HORA, MINUTO Y SEGUNDO
setInterval('contar(2008,07,06,00,01,0,' id ')',1000);

</script>

<script type='text/javascript'>

function contar(ayo,mes,dia,hora,minuto,segundo,id) {

/*
Autor 1: pepe
http:www.forosdelweb.com/f13/contador-cuenta-atras-356428/#post1357499

Autor 2: Chris Meichtry
http:www.mambosphere.com

Autor 3 (Modificador y recopilador): JoniJnm
htp://www.jonijnm.es
*/
  var dif = dia + ' del ' + mes + ' de ' + ayo + ', a las ' + hora + ':';
  if (minuto < 10) { dif+='0'; }
  dif+=minuto + '<br>';
  document.getElementById('evento' + id).innerHTML=dif
  var a = new Date();
  //hora, minuto,segundo, mes,dia a?o.
  var dif= mktime(hora,minuto,segundo,mes - 1,dia,ayo) - mktime(a.getHours(),a.getMinutes(),a.getSeconds(),a.getMonth(),a.getDate(), a.getFullYear());
  if (dif < 0) { document.getElementById('contar' + id).innerHTML="<font color='#FF0000'>Lleg&oacute; el evento!!</font>"; }
  else {
    dia= Math.floor(dif/60/60/24);  
    hora= Math.floor((dif - dia*60*60*24)/60/60);
    minuto= Math.floor((dif - dia*60*60*24 - hora*60*60)/60);
    segundo= Math.floor(dif - dia*60*60*24 - hora*60*60 - minuto*60);
    var txt = '';
    if (dia > 0) {
        txt=dia+' d&iacute;a';
        if (dia != 1) { txt+='s'; }
        txt+= '<br>';
    }
    if (hora > 0 || dia > 0) {
        txt+=hora+' hora';
        if (hora != 1) { txt+='s'; }
        txt+= '<br>';
    }
    if (minuto > 0 || hora > 0 || dia > 0) {
        txt+=minuto+' minuto';
        if (minuto != 1) { txt+='s'; }
        txt+= '<br>';
    }
    txt+=segundo+' segundo';
    if (segundo != 1) { txt+='s'; }
    document.getElementById('contar' + id).innerHTML=txt;
    }

function mktime() {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: baris ozdil
    // +      input by: gabriel paderni 
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: FGFEmperor
    // +      input by: Yannoo
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: mktime( 14, 10, 2, 2, 1, 2008 );
    // *     returns 1: 1201871402
    
    var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
    d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
 
    var dateManip = {
        0: function(tt){ return d.setHours(tt); },
        1: function(tt){ return d.setMinutes(tt); },
        2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
        3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
        4: function(tt){ return d.setDate(tt+mb); },
        5: function(tt){ return d.setYear(tt+ma); }
    };
    
    for( i = 0; i < argc; i++ ){
        no = parseInt(argv[i]*1);
        if(no && isNaN(no)){
            return false;
        } else if(no){
            // arg is number, let's manipulate date object
            if(!dateManip[i](no)){
                // failed
                return false;
            }
        }
    }
 
    return Math.floor(d.getTime()/1000);
}

}
</script> 
Descargar como módulo para Joomla

Última edición por JoniJnm; 04/07/2008 a las 23:39