Étape 3: fonctions.
[code]
< script type = « text/javascript » >
/***********************************************
* JavaScript Image horloge - par JavaScript Kit (www.javascriptkit.com)
* Le présent avis doit rester intacte pour l’utilisation
* Visitez JavaScript Kit à http://www.javascriptkit.com/ pour ce script et 100 plus
***********************************************/
var imageclock = new Object()
Entrez le chemin d’accès à l’horloge chiffres images ici, dans l’ordre de 0 à 9, puis « am/pm », puis l’image du côlon :
imageclock.digits=["C0.gif", "c1.gif", "c2.gif", "c3.gif", "c4.gif", "c5.gif", "c6.gif", "c7.gif", "c8.gif", "c9.gif", "cam.gif", "cpm.gif", "colon.gif"]
imageclock.instances=0
var preloadimages =]
pour (var i = 0; i < imageclock.digits.length; i ++) {//preload images
preloadimages [i] = new Image()
preloadimages [i] SRC = imageclock.digits [i]
}
imageclock.imageHTML=function(timestring) {//return timestring (c’est à dire: 01:56:38) dans la chaîne d’images à la place
var sections=timestring.split(":")
Si (sections[0]=="0") //If heure champ est 0 (aka 12 AM)
sections [0] = « 12 »
ElseIf (sections [0] > = 13)
sections [0] = sections [0]-12 + ""
pour (var i = 0; i < sections.length; i ++) {}
Si (sections[i].length==1)
sections [i] ='< img src="'+imageclock.digits[0]+" "/ > '+' < img src="'+imageclock.digits[parseInt(sections[i])] + "" / > "
d’autre
sections [i] ='< img src="'+imageclock.digits[parseInt(sections[i].charAt(0))] +" "/ > '+' < img src="'+imageclock.digits[parseInt(sections[i].charAt(1))] + "" / > "
}
retour sections [0] +'< img src="'+imageclock.digits[12]+" "/ >'+ les sections [1] +'< img src="'+imageclock.digits[12]+ "" / >'+ Articles [2]
}
{imageclock.Display=Function()}
var clockinstance = cela
This.spanid="clockspan"+(imageclock.instances++)
document.Write ('< span id="'+this.spanid+'" >< / span >')
This.Update()
setInterval(function(){clockinstance.update()}, 1000)
}
{imageclock.Display.prototype.Update=Function()}
var dateobj = new Date()
var currenttime=dateobj.getHours() + ":" +dateobj.getMinutes()+":"+dateobj.getSeconds() //create chaîne de temps
var currenttimeHTML=imageclock.imageHTML(currenttime) +'< img src="'+((dateobj.getHours() > = 12)? imageclock.digits[11]: imageclock.digits[10])+" "/ >"
document.getElementById (this.spanid) .innerHTML = currenttimeHTML
}
< /script >
[/ code]
Devront aller dans l’en-tête. mais vous avez encore besoin d’un peu de javascript pour profiter de lui.
Page entière :
[code]
< html >
< tête >
< script type = « text/javascript » >
/***********************************************
* JavaScript Image horloge - par JavaScript Kit (www.javascriptkit.com)
* Le présent avis doit rester intacte pour l’utilisation
* Visitez JavaScript Kit à http://www.javascriptkit.com/ pour ce script et 100 plus
***********************************************/
var imageclock = new Object()
Entrez le chemin d’accès à l’horloge chiffres images ici, dans l’ordre de 0 à 9, puis « am/pm », puis l’image du côlon :
imageclock.digits=["C0.gif", "c1.gif", "c2.gif", "c3.gif", "c4.gif", "c5.gif", "c6.gif", "c7.gif", "c8.gif", "c9.gif", "cam.gif", "cpm.gif", "colon.gif"]
imageclock.instances=0
var preloadimages =]
pour (var i = 0; i < imageclock.digits.length; i ++) {//preload images
preloadimages [i] = new Image()
preloadimages [i] SRC = imageclock.digits [i]
}
imageclock.imageHTML=function(timestring) {//return timestring (c’est à dire: 01:56:38) dans la chaîne d’images à la place
var sections=timestring.split(":")
Si (sections[0]=="0") //If heure champ est 0 (aka 12 AM)
sections [0] = « 12 »
ElseIf (sections [0] > = 13)
sections [0] = sections [0]-12 + ""
pour (var i = 0; i < sections.length; i ++) {}
Si (sections[i].length==1)
sections [i] ='< img src="'+imageclock.digits[0]+" "/ > '+' < img src="'+imageclock.digits[parseInt(sections[i])] + "" / > "
d’autre
sections [i] ='< img src="'+imageclock.digits[parseInt(sections[i].charAt(0))] +" "/ > '+' < img src="'+imageclock.digits[parseInt(sections[i].charAt(1))] + "" / > "
}
retour sections [0] +'< img src="'+imageclock.digits[12]+" "/ >'+ les sections [1] +'< img src="'+imageclock.digits[12]+ "" / >'+ Articles [2]
}
{imageclock.Display=Function()}
var clockinstance = cela
This.spanid="clockspan"+(imageclock.instances++)
document.Write ('< span id="'+this.spanid+'" >< / span >')
This.Update()
setInterval(function(){clockinstance.update()}, 1000)
}
{imageclock.Display.prototype.Update=Function()}
var dateobj = new Date()
var currenttime=dateobj.getHours() + ":" +dateobj.getMinutes()+":"+dateobj.getSeconds() //create chaîne de temps
var currenttimeHTML=imageclock.imageHTML(currenttime) +'< img src="'+((dateobj.getHours() > = 12)? imageclock.digits[11]: imageclock.digits[10])+" "/ >"
document.getElementById (this.spanid) .innerHTML = currenttimeHTML
}
< /script >
< tête >
< corps >
< script type = « text/javascript » >
nouveau imageclock.display()
< /script >
< / body >
< / html >
[/ code]