Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function picswap(imgRef)
- 2{
- 3 this.period=600;
- 4 this.timer=null;
- 5 this.index=0;
- 6 this.theElem=document.getElementById(imgRef);
- 7 this.defSrc=this.theElem.src;
- 8 this.imgData=[];
- 9
- 10 for(var i=0; i<3; i++)
- 11 {
- 12 this.imgData[i]=new Image();
- 13 if(i==0) {
- 14 this.imgData[i].src=this.theElem.src.replace('.1.png','.'+i+'.png');
- 15 } else if (i==1) {
- 16 this.imgData[i].src=this.theElem.src.replace('.1.png','.2.png');
- 17 } else {
- 18 this.imgData[i].src=this.theElem.src.replace('.1.png','.3.png');
- 19 }
- 20 }
- 21
- 22 this.trigElem = (this.theElem.parentNode.tagName=='A' ? this.theElem.parentNode : this.theElem);
- 23
- 24 this.trigElem.onmouseout=this.trigElem.onblur=(function(obj){ return function()
- 25 { clearInterval(obj.timer);
- 26 obj.theElem.src=obj.defSrc;
- 27 obj.index=0;
- 28 }})(this);
- 29
- 30 this.trigElem.onmouseover=this.trigElem.onfocus=(function(obj){return function()
- 31 {
- 32 obj.trigElem.onmouseout();
- 33 obj.timer=setInterval( (function(inst){return function(){inst.swap()}})(obj), obj.period);
- 34 }})(this);
- 35
- 36 this.swap=function(/*73637269707465726C61746976652E636F6D*/)
- 37 {
- 38 if(this.index==this.imgData.length)
- 39 this.index=0;
- 40 this.theElem.src=this.imgData[ this.index++ ].src;
- 41 }
- 42}
Add Comment
Please, Sign In to add comment