Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<style type="text/css">
/*<![CDATA[*/
#tst {
position:relative;overflow:hidden;top:300px;width:350px;height:100px;
}
#tst IMG {
position:relative;width:100px;height:100px;
}
/*]]>*/
</style></head>
<body>
<div id="tst" >
<img class="digit" src="http://www.vicsjavascripts.org.uk/StdImages/Zero.gif" alt="0" />
<img class="digit" src="http://www.vicsjavascripts.org.uk/StdImages/Zero.gif" alt="0" />
<img class="digit" src="http://www.vicsjavascripts.org.uk/StdImages/Zero.gif" alt="0" />
</div>
<script type="text/javascript">
/*<![CDATA[*/
// Odometer (09-October-2011)
// by Vic Phillip http://www.vicsjavascripts.org.uk/
function zxcOdometer(o){
var el=document.getElementById(o.ID),reg=new RegExp('\\b'+o.CommonClass+'\\b'),els=el.getElementsByTagName('IMG'),ary=[],z0=0,z1=0,img,srcary=o.ImageArray,z2=0,ms=o.SlideDuration;
for (;z0<els.length;z0++){
if(reg.test(els[z0].className)){
ary.push([els[z0],els[z0].offsetLeft]);
}
}
this.f=ary[0][0].height;
for (;z1<ary.length;z1++){
img=ary[z1][0].cloneNode(true);
img.style.position='absolute';
img.style.left=ary[z1][1]+'px';
img.style.top=ary[z1][0].height+'px';
el.appendChild(img);
ary[z1][0].style.position='absolute';
ary[z1][0].style.left=ary[z1][1]+'px';
ary[z1][0].style.top='0px';
ary[z1]=new zxcOdometerSlide(img,ary[z1][0],typeof(ms)=='number'?ms:500);
}
ary=ary.reverse();
for (;z2<srcary.length;z2++){
img=new Image();
img.src=srcary[z2];
srcary[z2]=img;
}
this.ary=ary;
this.srcary=srcary;
this.nu=1;
}
zxcOdometer.prototype.Count=function(){
var z0=0,ary=this.ary,cnt=1;
for (;z0<ary.length;z0++){
if (this.nu%cnt==0||z0==0){
ary[z0].img.src=this.srcary[ary[z0].cnt].src;
ary[z0].cnt=++ary[z0].cnt%10;
ary[z0].obj.src=this.srcary[ary[z0].cnt].src;
ary[z0].animate('top',this.f,0,new Date());
}
cnt*=10;
}
this.nu++;
}
function zxcOdometerSlide(obj,img,ms){
this.obj=obj;
this.img=img;
this.ms=ms;
this.cnt=0;
}
zxcOdometerSlide.prototype.animate=function(mde,f,t,srt){
var oop=this,ms=new Date().getTime()-srt,mS=this.ms,now=(t-f)/mS*ms+f;
if (isFinite(now)){
this.obj.style[mde]=now+'px';
this.img.style[mde]=now-f+'px';
}
if (ms<mS){
this.dly=setTimeout(function(){ oop.animate(mde,f,t,srt); },10);
}
}
M1=new zxcOdometer({
ID:'tst', // the unique ID name of the parent DIV element. (string)
CommonClass:'digit', // the common class name of the images. (string)
ImageArray:[ // the file path and name of the images. (array)
'http://www.vicsjavascripts.org.uk/StdImages/Zero.gif',
'http://www.vicsjavascripts.org.uk/StdImages/One.gif',
'http://www.vicsjavascripts.org.uk/StdImages/Two.gif',
'http://www.vicsjavascripts.org.uk/StdImages/Three.gif',
'http://www.vicsjavascripts.org.uk/StdImages/Four.gif',
'http://www.vicsjavascripts.org.uk/StdImages/Five.gif',
'http://www.vicsjavascripts.org.uk/StdImages/Six.gif',
'http://www.vicsjavascripts.org.uk/StdImages/Seven.gif',
'http://www.vicsjavascripts.org.uk/StdImages/Eight.gif',
'http://www.vicsjavascripts.org.uk/StdImages/Nine.gif'
],
SlideDuration:200 //(optional) the slide duration in milli seconds. (number, default = 500)
});
setInterval(function(){ M1.Count(); },600);
/*]]>*/
</script>
</body>
</html>
Bookmarks