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>
</head>
<body>
<div id="d1" style="position:relative;left:200px;top:200px;width:100px;height:190px;border:solid red 1px" ></div>
<div id="d2" style="position:relative;left:200px;top:400px;width:100px;height:100px;" ></div>
<script type="text/javascript">
/*<![CDATA[*/
var zxcSpinner={
Direction:function(id,d){
var o=this['zxc'+id];
if (o){
o.dir=typeof(d)=='number'?d<0?-1:1:o.dir;
this.stg(o);
}
},
Mode:function(id,m){
var o=this['zxc'+id];
o?o.mde=typeof(m)=='string'&&m.charAt(0).toUpperCase()=='V'?'V':'H':null;
},
Speed:function(id,s){
var o=this['zxc'+id];
o?o.spd=Math.max(typeof(s)=='number'?s:50,20):null;
},
Pause:function(id){
var o=this['zxc'+id];
if (o){
clearTimeout(o.to);
o.run=false;
}
},
Auto:function(id){
var oop=this,o=this['zxc'+id];
if (o){
o.to=setTimeout(function(){ oop.rotate(o); },250);
}
},
init:function(o){
var id=o.ID,m=o.Mode,sides=o.Sides,ary=o.Images,s=o.Speed,d=o.Direction,p=document.getElementById(id),lgth=ary.length,pw=p.offsetWidth,ino=lgth+1,imn=2*lgth,sides=typeof(sides)=='number'?sides:lgth,sides=Math.min(Math.max(sides,2),lgth*2),faces=Math.ceil(sides/2),px=[],o,z0=0;
for(var z0=0;z0<lgth;z0++){
px[z0]=p.appendChild(document.createElement("img"))
px[z0].src=ary[z0];
px[z0+lgth]=px[z0];
px[z0].style.position='absolute';
px[z0].style.border="solid 1px blue"
if(lgth==faces){
px[z0+2*lgth]=px[z0]
}
}
this['zxc'+id]=o={
px:px,
imgw:[],
imgx:[],
faces:faces,
sides:sides,
pw:pw,
lgth:lgth,
ino:lgth+1,
imn:2*lgth,
cnt:0,
dir:1,
run:true
}
this.Speed(id,s);
this.Direction(id,d);
this.Mode(id,m);
this.addevt(p,'mouseover','Pause',id);
this.addevt(p,'mouseout','Auto',id);
this.rotate(o);
},
stg:function(o){
var fo=Math.floor(o.pw*Math.cos(Math.PI/o.sides)/Math.sin(Math.PI/o.sides)/2),tpi=0.2*Math.PI/o.sides,z0=0;
for(;z0<=10*o.faces;z0++){
o.imgw[z0]=o.pw*Math.sin(tpi*z0);
o.imgx[z0]=Math.floor(o.pw+o.dir*fo*Math.cos(tpi*z0)-o.imgw[z0]/2);
}
},
rotate:function(o){
if(++o.cnt>=10){
o.cnt=0;
if(++o.ino>=o.imn){
o.ino=o.lgth
}
}
var oop=this,m=o.mde=="V"?['top','left','width','height']:['left','top','height','width'],z0=0;
o.px[o.ino-o.faces].style[m[0]]='-5000px'
for(;z0<o.faces;z0++){
o.px[o.ino-z0].style[m[0]]=o.imgx[o.cnt+z0*10]+'px';
o.px[o.ino-z0].style[m[1]]='0px';
o.px[o.ino-z0].style[m[2]]=o.pw+'px';
o.px[o.ino-z0].style[m[3]]=o.imgw[o.cnt+z0*10]+'px'
}
o.to=setTimeout(function(){ oop.rotate(o); },o.spd);
},
addevt:function(o,t,f,p){
var oop=this;
if (o.addEventListener){
o.addEventListener(t,function(e){ return oop[f](p);}, false);
}
else if (o.attachEvent){
o.attachEvent('on'+t,function(e){ return oop[f](p); });
}
}
}
zxcSpinner.init({
ID:'d1', // the unique ID name of the parent DIV. (string)
Images:[ // an array of image SRCs. (array)
'http://www.vicsjavascripts.org.uk/StdImages/1.gif',
'http://www.vicsjavascripts.org.uk/StdImages/2.gif',
'http://www.vicsjavascripts.org.uk/StdImages/3.gif',
'http://www.vicsjavascripts.org.uk/StdImages/4.gif'
],
Mode:'V', //(optional) the mode of execution, 'Horizontal' or 'Vertical'. (string, default = 'Horizontal')
Sides:6, //(optional) the number of sides. (number, default = the number of Images )
Direction:-1 //(optional) the rotation direction, 1 = anti-clock, -1 = clockwise. (number, default = 1)
});
zxcSpinner.init({
ID:'d2',
Mode:'H',
Sides:8,
Images:[
'http://www.vicsjavascripts.org.uk/StdImages/1.gif',
'http://www.vicsjavascripts.org.uk/StdImages/2.gif',
'http://www.vicsjavascripts.org.uk/StdImages/3.gif',
'http://www.vicsjavascripts.org.uk/StdImages/4.gif'
]
});
/*]]>*/
</script>
</body>
</html>
Bookmarks