Hej Emil,
Her der der noget tekst der skiftes ud. Du kan bruge det til grundlag.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da">
<head>
<title>Nedtælling til nytårsaften</title>
</head>
<body>
<h1>Nedtælling til nytårsaften</h1>
<p>
<div id="test"></div>
<script type="text/javascript">
/**
* @class Countdown
* @param {string/HTMLElement} el target HTMLElement or id of target HTMLElement.
* @param {string/Date Object} time target time to countdown to.
*/
var CountDown = function(el, time) {
if(!el.innerHTML) {
el = document.getElementById(el);
}
this.el = el;
if(typeof target != "object") {
time = new Date(time);
}
this.target = time;
}
CountDown.prototype = {
/**
* Gets distance in seconds
* @return {number}
*/
getDist : function() {
var now = new Date();
var dist = now.getTime() - this.target.getTime();
return Math.abs(dist);
},
/**
* Gets calculated distance
* @return {object}
*/
getCount : function() {
var dist = this.getDist();
var second = 1000
var minute = 60 * second;
var hour = 60 * minute;
var day = 24 * hour;
var days = Math.floor(dist / day);
var hours = Math.floor((dist - (days*day)) / hour);
var minutes = Math.floor((dist - (days*day+hours*hour)) / minute);
var seconds = Math.floor((dist - (days*day+hours*hour+minutes*minute)) / second);
return {
"days" : days, "hours" : hours, "minutes" : minutes, "seconds" : seconds
}
},
/**
* starts countdown
*/
start : function() {
var c = this.getCount()
this.el.innerHTML = c.days + 'days '+c.hours+'hours '+c.minutes+'minutes '+c.seconds+'seconds';
var fn = function(that) {
that.start.call(that);
}
this.timer = setTimeout(fn,1000,this);
},
/**
* stops countdown
*/
stop : function() {
clearTimeout(this.timer);
}
}
window.onload = function() {
var cd = new CountDown("test", new Date('Jan 01 2008 16:00:01'));
cd.start();
}
</script>
</p>
</body>
</html>
Med venlig hilsen
Ieet