Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Countdown diversi

  1. #1

    Countdown diversi

    Codice PHP:
    <script type="text/javascript">
    function 
    countdownTime(idnumberfine) {
    now = new Date().getTime();
    diff fine now;
    ore Math.Floordiff / (1000*60*60) );
    mn Math.Floordiff / (1000*60) );
    sec Math.Floordiff 1000 );

    hh ore;
    mm mn ore 60;
    ss sec mn 60;
    countid 'count' idnumber;

            
    document.getElementById(countid).innerHTML=hh ':' mm ':' ss;
            if(
    diff 0){
            
    document.getElementById(countid).innerHTML="Allenamento finito";
           }
    }
    setInterval(countdownTime(),1000);
    </script> 
    Ciao lo script sopra dovrebbe cambiare nella cella di ogni record diverso un countdown in base a quando finirà l'allenamento...lo stile della cella viene cambiato e quindi il codice viene eseguito,ma all'interno non mi appare nulla..cosa sbaglio?

  2. #2
    Utente di HTML.it L'avatar di carlomarx
    Registrato dal
    Oct 2009
    Messaggi
    1,669
    Liberamente tratto da qui... http://forum.html.it/forum/showthrea...2#post13813382:

    codice:
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>CountDown</title>
    <script type="text/javascript">
    function Timer (oNode, sGMTDate) {
    	if (arguments.length < 2) { throw new TypeError("Timer - not enough arguments"); }
    	this.expires = Date.parse(sGMTDate) || 0x1f3fffffc18;
    	this.owner = oNode;
    	Timer.instances.push(this);
    }
    
    Timer.refreshAll = function () {
    	for (var nDelta, nDLeft, nHLeft, nMLeft, nSLeft, oThis, oDisplay, nInst = 0; nInst < Timer.instances.length; nInst++) {
    		oThis = Timer.instances[nInst];
    		if (!oThis) { continue; }
    		nDelta = oThis.expires - Date.now();
    		/* Casual expiration test */
    		// if (Math.floor(Math.random() * 8) === 0) { nDelta = 0; }
    		if (nDelta <= 0) {
    			Timer.instances[nInst] = null;
    			oThis.owner.innerHTML = "Tempo scaduto";
    			continue;
    		}
    		nDLeft = Math.floor(nDelta / 864e5);
    		nDelta -= (nDLeft * 864e5);
    		nHLeft = Math.floor(nDelta / 36e5);
    		nDelta -= (nHLeft * 36e5);
    		nMLeft = Math.floor(nDelta / 6e4);
    		nDelta -= (nMLeft * 6e4);
    		nSLeft = Math.floor(nDelta / 1e3);
    		nDelta -= (nSLeft * 1e3);
    		oThis.owner.innerHTML = nDLeft + " giorni, " + nHLeft + " ore, " + nMLeft + " minuti e " + nSLeft + " secondi";
    	}
    };
    
    Timer.instances = [];
    
    Timer.session = setInterval(Timer.refreshAll, 1000);
    
    onload = function () {
    	for (var aTimers = document.getElementsByClassName("countdown"), oTimer, nLen = aTimers.length, nItem = 0; nItem < nLen; nItem++) {
    		oTimer = aTimers[nItem];
    		if (!oTimer.hasAttribute("data-expires")) { continue; }
    		new Timer(oTimer, oTimer.getAttribute("data-expires"));
    	}
    	Timer.refreshAll();
    };
    
    </script>
    </head>
    
    <body>
    
    <div class="countdown" data-expires="Thu, 10 Jun 2088 22:36:43 GMT"></div>
    <div class="countdown" data-expires="Sat, 22 Apr 2215 05:15:19 GMT"></div>
    <div class="countdown" data-expires="Sun, 12 Jan 2251 08:22:20 GMT"></div>
    
    </body>
    
    </html>
    Tutto ciò che fai con jQuery puoi farlo meglio e con la metà del codice in puro JavaScript.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.