1 頁 (共 1 頁)

[修改]倒數計時功能

發表於 : 2002-10-24 18:03
動機不明
慶祝竹貓即將滿週歲,提供這個小東東 :)
這個外掛不需要改太多地方,只有一個:index_body.tpl
找適當位置加入下列java語法即可

代碼: 選擇全部

<!-- 倒數計時開始 -->
<script language="JavaScript1.2">
function setcountdown(theyear,themonth,theday,thehour,themin,thesec){yr=theyear;mo=themonth;da=theday;hr=thehour;min=themin;sec=thesec}
//Count down to date. format: year, month, day, hour, minute, second
setcountdown(2002,10,29,00,00,00)

//the event msg and msg when its the time of the event
var occasion="距離竹貓星球的週年紀念日還有"
var message_on_occasion="<b><font color=FF0000; size=5>今天是竹貓星球的週年紀念日喔!</font></b>"

//text hieght, width, bgcolor etc. subSilver default
var countdownwidth='100%'
var countdownheight='35px'
var countdownbgcolor='#F4ECDD'
var opentags='<span class="gensmall">'
var closetags='</span>'

//////////DO NOT EDIT PAST 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+" "+hr+":"+min+":"+sec
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+"倒數計時事件時間已過!"+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"目前沒有倒數事件"+closetags
return
}
//else, if not yet
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+occasion+ "倒數計時:"+dday+ " 天, "+dhour+" 小時, "+dmin+" 分 "+dsec+" 秒"+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+occasion+dday+ " 天, "+dhour+" 小時, "+dmin+" 分 "+dsec+" 秒 "+closetags
}
setTimeout("countdown()",1000)
}
</script>
<!-- End of javascript -->
<ilayer id="countdownnsmain" width=&{countdownwidth}; height=&{countdownheight}; bgColor=&{countdownbgcolor}; visibility=hide><layer id="countdownnssub" width=&{countdownwidth}; height=&{countdownheight}; left=0 top=0></layer></ilayer>
<!-- 倒數計時結束 -->
由於原始碼我有修改過 ^^bb (主要是因為要改成中文),現在說明一下

代碼: 選擇全部

//Count down to date. format: year, month, day, hour, minute, second
setcountdown([color=red]2002,10,29,00,00,00[/color])
設定開始倒數的時間及日期

代碼: 選擇全部

//the event msg and msg when its the time of the event
var occasion="[color=red]距離竹貓星球的週年紀念日還有[/color]"
var message_on_occasion="<b><font color=FF0000; size=5>今天是竹貓星球的週年紀念日喔!</font></b>"
設定 倒數 時的顯示字串以及計時到之後的顯示字串\r

代碼: 選擇全部

//text hieght, width, bgcolor etc. subSilver default
var countdownwidth='100%'
var countdownheight='35px'
var countdownbgcolor='[color=red]#F4ECDD[/color]'
var opentags='<span class="gensmall">'
var closetags='</span>'
設定寬與高,以及背景顏色

發表於 : 2002-10-28 01:09
oO]-[Oo
多謝囉 (:Y)

發表於 : 2002-10-28 01:12
majimmy
字體不明顯\r

改在公告ㄉ那個地方\r
也不錯喔 :D

發表於 : 2002-10-28 01:14
小竹子
對呀!
表哥顏色改成橘色然後字體弄大一點