Guest User

Untitled

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