Guest User

newsticker-marquee-ersatz

a guest
Jul 19th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function NewsTicker()
  2. {
  3.     this.container = null;
  4.     this.text = "";
  5.     this.index = 0;
  6.     this.len = 0;
  7.     this.othercolor = false;
  8. }
  9.  
  10. NewsTicker.prototype.init = function()
  11. {
  12.     div = document.getElementById("newsticker");
  13.     if(div)
  14.     {
  15.         this.container = div;
  16.         this.text = div.innerHTML;
  17.     }
  18. }
  19.  
  20. NewsTicker.prototype.loop = function()
  21. {
  22.     if(this.container == null)
  23.     {
  24.         this.init();
  25.         window.setTimeout("newsticker.loop()","250");
  26.     }
  27.     else
  28.     {
  29.         this.index++;
  30.         if(this.index>=this.text.length)
  31.         {
  32.             this.index = 0;
  33.             this.othercolor = !this.othercolor;
  34.         }
  35.        
  36.         if(this.othercolor)
  37.             this.container.innerHTML = "<font color=#00ff00>"+this.text.substring(this.index)+"</font> "+this.text.substring(0,this.index);
  38.         else
  39.             this.container.innerHTML = this.text.substring(this.index)+" <font color=#00ff00>"+this.text.substring(0,this.index)+"</font>";
  40.    
  41.         window.setTimeout("newsticker.loop()","125");  
  42.     }
  43. }
  44.  
  45. window.newsticker = new NewsTicker();
  46. window.newsticker.loop();
Advertisement
Add Comment
Please, Sign In to add comment