Forenindex » Programmierung/Entwicklung » JavaScript » Countdown-Script

Countdown-Script

Freakezoid
Beiträge gesamt: 1

27. Dez 2004, 20:14
Bewertung:

gelesen: 1248

Beitrag als Lesezeichen
Hallo,
Ich habe im Internet folgendes Script gefunden:


<table style="width:{$style['tableinwidth']}">
<tr>
<td align="center"><span class="tabletitle">
<script language="JavaScript1.2">
function setcountdown(theyear,themonth,theday) {
yr=theyear;mo=themonth;da=theday
}

setcountdown(2005,01,01)

var occasion="Jahreswechsel 2005!"
var message_on_occasion="<b>ALLEN USERN VON $master_board_name EIN FROHES NEUES JAHR !</b>"
var countdownwidth='510px'
var countdownheight='22px'
var countdownbgcolor=''
var opentags=''
var closetags=''
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+ " Tage, "+dhour+" Stunden, "+dmin+" Minuten und "+dsec+" Sekunden bis "+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>
</span></td>
</table>





Ich mag eigentlich alles an dem Script. Nur will ich nicht den Countdownzähler für den 1.1.2005 sondern jeweils andere Daten. Ich habe kapiert, wo man das Datum ändern kann. Das einzige Problem, das ich da habe ist, dass dieses Countdownscript immer auf ein bestimmtes Datum um 0:00 zählt. Ich will aber das Datum 29.12.2004 um 11:00h als Zielzeit. Kann mir jemand das Script umschreiben oder mir sonst weiterhelfen? Danke für all eure Hilfe!!!

Countdown-Script

Markus Walker
Beiträge gesamt: 494

28. Dez 2004, 15:50
Bewertung:

gelesen: 1248

Beitrag als Lesezeichen
Hallo

Studier mal die Möglichkeiten des Date-Objekts:
http://de.selfhtml.org/...ipt/objekte/date.htm

Dann wird Die sofort klar, was in den folgenden Zeilen abläuft und wie Du das Verhalten entsprechend manipulieren kannst:

function setcountdown(theyear,themonth,theday) {
yr=theyear;mo=themonth;da=theday
}
setcountdown(2005,01,01)
/*
Diese Funktion ist eher seltsam und hat einzig zum Ziel, dass das Datum in der letzten Zeile in gewohnter Art eingegeben werden kann. Sie liesse sich natürlich erweitern, um Ziel-Stunde und -Minute auch zu erfassen.
*/

futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
/*
Hier wird nun das Datum für JavaScript zusammengesetzt und die Zeit in Millisekunden zwischen ‹jetzt› und dem betreffenden Datum ermittelt.
*/


HTH