|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Mar 2006
Messaggi: 139
|
[Javascript] Creare un countdown-
Salve!
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Quote:
Comunque per il countdown, avevo postato un mio esempio in <questa> discussione.
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
|
#4 |
|
Member
Iscritto dal: Mar 2006
Messaggi: 139
|
Farebbe al caso mio uno script del genere ma putroppo è sprovvisto di "orario" (solo mese,giorno, ed anno c'è).
Codice:
<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>
|
|
|
|
|
|
#5 |
|
Member
Iscritto dal: Mar 2006
Messaggi: 139
|
Anche qualcosa di simile basta che mi indica l'anno,il mese, il giorno e l'orario che manca per un determinato evento,thanks!
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#7 | |
|
Member
Iscritto dal: Mar 2006
Messaggi: 139
|
Quote:
![]() P.S: Sono un rompi..bipppp lo so ma mi servirebbe uno script senza copyright ne pubblicità varie. Ultima modifica di Robinho : 26-09-2007 alle 11:53. |
|
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
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)
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
questo ti dovrebbe calzare
Codice:
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);}}
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#10 |
|
Member
Iscritto dal: Mar 2006
Messaggi: 139
|
"isAlreadyInUse" grazie, ma mi pare che non funziona!
"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? |
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Ho messo all'inizio delle variabili from_XXX che definiscono la data limite.
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
#12 |
|
Member
Iscritto dal: Mar 2006
Messaggi: 139
|
cioè quì?
Codice:
var from_year = 2007; var from_month = 1; var from_day = 1; var from_hour = 0; var from_minute = 0; var from_second = 0; |
|
|
|
|
|
#13 |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Sì.
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
#14 | |
|
Member
Iscritto dal: Mar 2006
Messaggi: 139
|
al tuo script ho modificato la data(cioè ho messo quello ke serviva a me...ossia 26 settembre alle 18) e.....
......mi esce...... Quote:
|
|
|
|
|
|
|
#15 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Quote:
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.
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
|
#16 | |
|
Member
Iscritto dal: Mar 2006
Messaggi: 139
|
QUESTO E' IL TUO SCRIPT
Codice:
<!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: Codice:
<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; Quote:
?????? |
|
|
|
|
|
|
#17 |
|
Member
Iscritto dal: Mar 2006
Messaggi: 139
|
Rinnovo nuovamente la richiesta d'aiuto...mi serve uno script x il countdown. HELP HELP!!!! Please!
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 07:54.





















