View Full Version : [Javascript] Creare un countdown-
Salve!:) Vorrei creare un conto alla rovescia per un evento, ho letto un pò in giro, ma non ho molta dimestichezza con il linguaggio Java....ho trovato 1 link in merito.... http://www.yappy.it/timer_eventi_javascript.php ho provato a creare il tutto come riportato nel link(ho usato dreamwever) ma nel mio sito poi non visualizzo alcun countdown. Qualcuno sa darmi una mano?O passarmi qualche link + utile ed info + specifiche di queste,please!:)
isAlreadyInUse
25-09-2007, 15:43
Tiè
http://www.crowes.f9.co.uk/Javascript/timer.htm
Salve!:) Vorrei creare un conto alla rovescia per un evento, ho letto un pò in giro, ma non ho molta dimestichezza con il linguaggio Java....ho trovato 1 link in merito.... Javascript non è Java, innanzitutto.
Comunque per il countdown, avevo postato un mio esempio in <questa> (http://www.hwupgrade.it/forum/showthread.php?t=1207958) discussione.
Farebbe al caso mio uno script del genere ma putroppo è sprovvisto di "orario" (solo mese,giorno, ed anno c'è).
<script language="JavaScript1.2">
/*
Dynamic countdown Script- © Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS,
visit http://www.dynamicdrive.com
*/
function setcountdown(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}
//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////
//STEP 1: Configure the countdown-to date, in the format year, month, day:
setcountdown(2003,12,25)
//STEP 2: Change the two text below to reflect the occasion, and message to display on that occasion, respectively
var occasion="Christmas!"
var message_on_occasion="Merry Christmas!"
//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countdown area
var countdownwidth='480px'
var countdownheight='20px'
var countdownbgcolor='lightblue'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'
//////////DO NOT EDIT PASS THIS LINE//////////////////
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''
function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie
countdown()
}
if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')
window.onload=start_countdown
function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
//if on day of occasion
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"Occasion already passed! "+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
return
}
//else, if not yet
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags
}
setTimeout("countdown()",1000)
}
</script>
<ilayer id="countdownnsmain" width=&{countdownwidth}; height=&{countdownheight}; bgColor=&{countdownbgcolor}; visibility=hide><layer id="countdownnssub" width=&{countdownwidth}; height=&{countdownheight}; left=0 top=0></layer></ilayer>
QUALCUNO PUO' AIUTARMI?:)
Anche qualcosa di simile basta che mi indica l'anno,il mese, il giorno e l'orario che manca per un determinato evento,thanks!;)
isAlreadyInUse
26-09-2007, 11:24
http://www.javascriptkit.com/script/script2/count2.shtml
http://www.javascriptkit.com/script/script2/count2.shtml
Sorry...ma in questo script non riesco a capire dove va inserito l'orario :doh: :help:
P.S: Sono un rompi..bipppp lo so ma mi servirebbe uno script senza copyright ne pubblicità varie.
Hai provato il countdown che avevo postato io?? (c'è solo da tirare in avanti la data .... l'avevo fatto nel 2006 e avevo messo come limite l'inizio del 2007)
isAlreadyInUse
26-09-2007, 12:06
questo ti dovrebbe calzare
var month = '*'; // 1 through 12 or '*' within the next month, '0' for the current month
var day = '1'; // day of month or + day offset
var dow = 0; // day of week sun=1 sat=7 or 0 for whatever day it falls on
var hour = 14; // 0 through 23 for the hour of the day
var tz = 10; // offset in hours from UTC to your timezone
var lab = 'cd'; // id of the entry on the page where the counter is to be inserted
function start() {displayCountdown(setCountdown(month,day,hour,tz),lab);}
loaded(lab,start);
// Countdown Javascript
// copyright 20th April 2005, 17th November 2006 by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
// you may change the start function if required
var pageLoaded = 0; window.onload = function() {pageLoaded = 1;}
function loaded(i,f) {if (document.getElementById && document.getElementById(i) != null) f(); else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100);
}
function setCountdown(month,day,hour,tz) {var m = month; if (month=='*') m = 0; var c = setC(m,day,hour,tz); if (month == '*' && c < 0) c = setC('*',day,hour,tz); return c;} function setC(month,day,hour,tz) {var toDate = new Date();if (day.substr(0,1) == '+') {var day1 = parseInt(day.substr(1));toDate.setDate(toDate.getDate()+day1);} else{toDate.setDate(day);}if (month == '*')toDate.setMonth(toDate.getMonth() + 1);else if (month > 0) { if (month <= toDate.getMonth())toDate.setFullYear(toDate.getFullYear() + 1);toDate.setMonth(month-1);}
if (dow >0) toDate.setDate(toDate.getDate()+(dow-1-toDate.getDay())%7);
toDate.setHours(hour);toDate.setMinutes(0-(tz*60));toDate.setSeconds(0);var fromDate = new Date();fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());var diffDate = new Date(0);diffDate.setMilliseconds(toDate - fromDate);return Math.floor(diffDate.valueOf()/1000);}
function displayCountdown(countdn,cd) {if (countdn < 0) document.getElementById(cd).innerHTML = "Sorry, you are too late."; else {var secs = countdn % 60; if (secs < 10) secs = '0'+secs;var countdn1 = (countdn - secs) / 60;var mins = countdn1 % 60; if (mins < 10) mins = '0'+mins;countdn1 = (countdn1 - mins) / 60;var hours = countdn1 % 24;var days = (countdn1 - hours) / 24;document.getElementById(cd).innerHTML = days+' days + '+hours+' : '+mins+' : '+secs;setTimeout('displayCountdown('+(countdn-1)+',\''+cd+'\');',999);}}
"isAlreadyInUse" grazie, ma mi pare che non funziona!:eek: (nn ho fatto nulla,ho solo incollato)
"andbin" il tuo potrebbe andar bene ma avrei bisogno delle delucidazioni in merito:
Dove metto la data e l'ora del'evento al quale voglio che effettui stò benedetto countdown?
Dove metto la data e l'ora del'evento al quale voglio che effettui stò benedetto countdown?Ho messo all'inizio delle variabili from_XXX che definiscono la data limite.
cioè quì?
var from_year = 2007;
var from_month = 1;
var from_day = 1;
var from_hour = 0;
var from_minute = 0;
var from_second = 0;
cioè quì?
var from_year = 2007;
var from_month = 1;
var from_day = 1;
var from_hour = 0;
var from_minute = 0;
var from_second = 0;Sì.
al tuo script ho modificato la data(cioè ho messo quello ke serviva a me...ossia 26 settembre alle 18) e.....
......mi esce......Tempo rimanente fino alla data: Wed Sep 26 2007 18:00:00 GMT+0200 (ora solare Europa occidentale)
è normale????Dov'è il countdown?:eek:
al tuo script ho modificato la data(cioè ho messo quello ke serviva a me...ossia 26 settembre alle 18) e.....
......mi esce......
è normale????Ho semplicemente fatto stampare la data limite. Non è che è normale o non normale .... è una informazione che ho messo.
Dov'è il countdown?:eek:Dovrebbe essere sotto in carattere un po' più grande e in colore blu. Se non c'è posso solo supporre che hai introdotto qualche errore di sintassi o altro.
QUESTO E' IL TUO SCRIPT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Date Countdown</title>
<script type="text/javascript">
<!--
var from_year = 2007;
var from_month = 1;
var from_day = 1;
var from_hour = 0;
var from_minute = 0;
var from_second = 0;
var d1 = new Date (from_year, from_month-1, from_day, from_hour, from_minute, from_second);
var old_second = -1;
function countdown_format (d, h, m, s)
{
return "giorni: " + d + " / " +
"ore: " + h + " / " +
"minuti: " + m + " / " +
"secondi: " + s;
}
function countdown_update ()
{
var d2 = new Date ();
var new_second = d2.getSeconds ();
if (new_second != old_second)
{
var diff = d1 - d2;
var str;
if (diff > 0)
{
var seconds = Math.floor (diff / 1000) % 60;
var minutes = Math.floor (diff / 60000) % 60;
var hours = Math.floor (diff / 3600000) % 24;
var days = Math.floor (diff / 86400000);
str = countdown_format (days, hours, minutes, seconds);
}
else
str = "Data superata!";
document.getElementById("countdown").innerHTML = str;
old_second = new_second;
}
window.setTimeout (countdown_update, 100);
}
//-->
</script>
<style type="text/css">
<!--
#info { font: normal 16px sans-serif; color: red; }
#countdown { font: bold 25px sans-serif; color: blue; }
-->
</style>
</head>
<body onload="countdown_update()">
<p>
<span id="info">
Tempo rimanente fino alla data:
<b>
<script type="text/javascript">
<!--
document.write (d1);
//-->
</script>
</b>
</span>
<br>
<br>
<span id="countdown"></span>
</p>
</body>
</html>
Io ho solo cambiato la data e l'ora che serve a me x il countdown,ossia:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Date Countdown</title>
<script type="text/javascript">
<!--
var from_year = 2007;
var from_month = 9;
var from_day = 26;
var from_hour = 18;
var from_minute = 0;
var from_second = 0;
e con queste modifiche mi visualizza solo questa scritta: empo rimanente fino alla data: Wed Sep 26 2007 18:00:00 GMT+0200 (ora solare Europa occidentale)
??????:eek: :(
Rinnovo nuovamente la richiesta d'aiuto...mi serve uno script x il countdown. HELP HELP!!!! Please!
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.