Visualizzazione dei risultati da 1 a 6 su 6

Visualizzazione discussione

  1. #1
    Utente di HTML.it L'avatar di neo1976
    Registrato dal
    Mar 2015
    Messaggi
    379

    2 countdown nella stessa pagina

    ho inserito due countdown per il conto alla rovescia nella stessa pagina il problema è che imposto due date differenti ma nella pagina appaiono con la stessa data, questi sono i codici in js:

    il primo countdown:
    codice:
    var target_date = new Date("december 24, 2016").getTime() + (1000*3600*48); // set the countdown date
    var days, hours, minutes, seconds; // variables for time units
    
    
    var countdown = document.getElementById("tiles"); // get tag element
    
    
    getCountdown();
    
    
    setInterval(function () { getCountdown(); }, 1000);
    
    
    function getCountdown(){
    
    
        // find the amount of "seconds" between now and target
        var current_date = new Date().getTime();
        var seconds_left = (target_date - current_date) / 1000;
    
    
        days = pad( parseInt(seconds_left / 86400) );
        seconds_left = seconds_left % 86400;
             
        hours = pad( parseInt(seconds_left / 3600) );
        seconds_left = seconds_left % 3600;
              
        minutes = pad( parseInt(seconds_left / 60) );
        seconds = pad( parseInt( seconds_left % 60 ) );
    
    
        // format countdown string + set tag value
        countdown.innerHTML = "<span>" + days + "</span><span>" + hours + "</span><span>" + minutes + "</span><span>" + seconds + "</span>"; 
    }
    
    
    function pad(n) {
        return (n < 10 ? '0' : '') + n;
    }
    questo è il secondo countdown:

    codice:
    var target_date = new Date("may 24, 2017").getTime("countdown2") + (1000*3600*48); // set the countdown datevar days, hours, minutes, seconds; // variables for time units
    
    
    var countdown2 = document.getElementById("tiles2"); // get tag element
    
    
    getCountdown2("countdown2");
    
    
    setInterval(function () { getCountdown2("countdown2"); }, 1000);
    
    
    function getCountdown2(){
    
    
    	// find the amount of "seconds" between now and target
    	var current_date = new Date().getTime("countdown2");
    	var seconds_left = (target_date - current_date) / 1000;
    
    
    	days = pad( parseInt(seconds_left / 86400) );
    	seconds_left = seconds_left % 86400;
    		 
    	hours = pad( parseInt(seconds_left / 3600) );
    	seconds_left = seconds_left % 3600;
    		  
    	minutes = pad( parseInt(seconds_left / 60) );
    	seconds = pad( parseInt( seconds_left % 60 ) );
    
    
    	// format countdown2 string + set tag value
    	countdown2.innerHTML = "<span>" + days + "</span><span>" + hours + "</span><span>" + minutes + "</span><span>" + seconds + "</span>"; 
    }
    
    
    function pad(n) {
    	return (n < 10 ? '0' : '') + n;
    }
    Ultima modifica di neo1976; 23-05-2016 a 12:48

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.