Countdown con effetto sonoro

Nefyt

Utente Attivo
17 Apr 2012
1.102
0
0
Posto uno script fatto tanto per esercitazione che gestisce un countdown fatto da giorni/ore/minuti/secondi con un effetto sonoro funzionante correttamente solo su chrome, puo sempre essere fonte di spunto

pagina.html
Codice:
<script src="timer_s.js"></script>
<div id="timer" style="margin-top:20%;font-family:Arial,Helvetica,sans-serif;text-align:center;font-size:30px;"></div>

<script>
   
   timer.CallTimer(
   new Array(2,4,34,20),
   document.getElementById('timer'),
   'clock.mp3',
   'MyCallBackFunction()'
);
    
    function MyCallBackFunction(){ alert('Finish'); }
   
</script>

timer_s.js
Codice:
/*
 * Sound Timer
 */

var timer = {
    
    times : null,
    div : null,
    sound: null,
    func: null,
    Stop: false,
    
    CallTimer: function(time,div,sound,func){
        this.times = time;
        this.checkSet();
        this.div = div ? div : null;
        this.sound = sound ? sound : null;
        this.func = func ? func : null;
        this.StartTimer();
   },
   
   checkSet: function(){
       for(i=0;i<4;i++)
         this.times[i] = typeof this.times[i] === 'number' ? parseInt(this.times[i]) : 0;
   },
   
   StartTimer: function(){
       this.SpawnTextAndSound();
       this.checkStatus();
       if(!this.Stop)
       setTimeout('timer.StartTimer()',1000);
   },
   
   SpawnTextAndSound : function(){
       this.div.innerHTML = this.times[0]+' : '+this.times[1]+' : '+this.times[2]+' : '+this.times[3]+'<embed src=\''+this.sound+'\' hidden=true autostart=true>';
   },
   
   checkStatus : function(){
       if(this.times[3]==0 && this.times[2]==0 && this.times[1]==0 && this.times[0]==0){ setTimeout(this.func,0); this.Stop = true; }
       
       else if(this.times[3]==0 && this.times[2]>0){ this.times[3]=60; this.times[2]--; }
       else if(this.times[3]==0 && this.times[2]==0 && this.times[1]>0){ this.times[3]=60; this.times[2]=59; this.times[1]--; }
       else if(this.times[3]==0 && this.times[2]==0 && this.times[1]==0 && this.times[0]>0){ this.times[3]=60; this.times[2]=59; this.times[1]=24; this.times[0]--; }
       else this.times[3]--; 
   }
}
 
Ultima modifica:
Discussioni simili
Autore Titolo Forum Risposte Data
L Creare un countdown con giorno specifico della settimana PHP 3
T countdown da sistemare con i CSS... HTML e CSS 4
A Countdown js con variabile in php Javascript 16
A countdown modificabile con un click Javascript 1
P problema con il countdown per la fine dell'anno e per natale Javascript 13
S Fare un Countdown con flash Flash 0
L Countdown con script Javascript 4
A Limite minimo con countdown textarea Javascript 0
M Piccola intro con countdown!!! Presenta il tuo Sito 1
L countdown multiplo javascript Javascript 1
M Come fare un countdown in HTML? HTML e CSS 4
C Countdown bloccato? Javascript? Javascript 0
D [Javascript] [HTML] Countdown su Mobirise di 24 ore relative per ogni utente. Javascript 4
Alex1990000 [PHP] countdown 6 ore data PHP 9
Michaelweb93 [PHP] Creazione countdown a 72 ore PHP 1
G Countdown in secondi JS su pagina PHP Javascript 1
N Creazione countdown PHP 4
O Countdown jQuery jQuery 0
O Countdown jQuery Javascript 1
P countdown jquery jQuery 2
blips Countdown e Redirect Javascript 3
T Javascript e countdown multipli Javascript 1
T Countdown e timestamp PHP 0
S countdown in php e script per aprire 2 siti contemporanemante PHP 1
S countdown PHP 1
maxnegri Problema countdown Javascript 3
F Countdown / timer javascript Javascript 19
S Stampare un messaggio alla fine del countdown in Javascript Javascript 0
maxnegri Stampare un messaggio alla fine di un countdown in javascript Javascript 0
M Countdown in asp Classic ASP 0
E Domanda countdown PHP PHP 3
J Countdown Timer 2 Javascript 0
J Make a JavaScript Countdown Timer in OOP Javascript 0
J JavaScript Countdown Timer solution in OOP Javascript 0
T Countdown fra 2 date in ASP Classic ASP 12
M Differenza tra date e countdown PHP 3
J Top 10 Beautiful Christmas Countdown Timers Javascript 0
G Countdown per l'apertura di un sito Javascript 1
M Countdown script Javascript 1
M countdown Flash 0
M Countdown Server Side Classic ASP 0
C Conto alla rovescia - Countdown (al secondo) Javascript 1
G Countdown particolare Javascript 8
F access ricerca record con apostrofo. MS Access 0
F Cerco Hosting con VECCHIE versioni di php Hosting 0
C Come ricreare questo calcolatore di prezzi a step con woocommerce? WordPress 0
C Segnalo barra laterale di navigazione ASSENTE con Chrome Comunicazioni dallo Staff 5
G Guadagna dalla Vendita di Articoli Sponsorizzati con GuestPostMax.com! Guadagnare col Sito 0
P Hosting multidominio con Plesk Hosting 0
L Soluzione con INNER JOIN Database 0

Discussioni simili