Visualizzazione dei risultati da 1 a 6 su 6
  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

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Premesso che le date sono uguali per entrambi gli script "december 24, 2016" dovrai anche cambiare il nome alle funzioni e alle variabili altrimenti si sovrascrivono
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  3. #3
    Utente di HTML.it L'avatar di neo1976
    Registrato dal
    Mar 2015
    Messaggi
    379
    salve Andrea, avevo messo per sbaglio lo stesso script , ora ho messo quello giusto con le date e le variabili differenti, in cosa sbaglio?

  4. #4
    Utente di HTML.it L'avatar di neo1976
    Registrato dal
    Mar 2015
    Messaggi
    379
    nessuno che sappia darmi delle indicazioni?

  5. #5
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  6. #6
    Utente di HTML.it L'avatar di neo1976
    Registrato dal
    Mar 2015
    Messaggi
    379
    grazie andrea, sei stato gentilissimo

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.