<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, count,speed) {
if(!el.innerHTML) {
el = document.getElementById(el);
}
this.el = el;
this.count = count;
}
CountDown.prototype = {
/**
* returns value
*/
getCount : function(returnOnly) {
if(returnOnly !== false) {
return this.count
}
return this.count--
},
/**
* starts countdown
*/
start : function() {
this.el.innerHTML = this.getCount(false);
var fn = this._delegate(this.start,this);
this.timer = setTimeout(fn,1000);
},
/**
* stops countdown
*/
stop : function() {
clearTimeout(this.timer);
},
// private
_delegate : function(func,obj) {
return function() {
return func.apply(obj,[]);
}
}
}
window.onload = function() {
var cd = new CountDown("test",120);
cd.start();
}
</script>
og for tid er der denne:
http://www.udvikleren.dk/Thread.aspx?f=27&t=22856
Indlæg senest redigeret d. 21.01.2008 10:51 af Bruger #10216