Guest User

NewsTicker

a guest
Jul 19th, 2012
139
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.count = 0;
  7.     this.othercolor = false;
  8. }
  9.  
  10. NewsTicker.prototype.init = function()
  11. {
  12.     div = document.getElementById("newstickertext");
  13.     if(div)
  14.     {
  15.         textWidth = div.offsetWidth;
  16.         this.text = div.innerHTML;
  17.        
  18.         div = document.getElementById("newsticker");
  19.         this.container = div;  
  20.         containerWidth = div.offsetWidth;
  21.  
  22.         this.count = Math.ceil(containerWidth/textWidth);
  23.     }
  24. }
  25.  
  26. NewsTicker.prototype.loop = function()
  27. {
  28.     if(this.container == null)
  29.         this.init();
  30.     else
  31.     {
  32.         this.index++;
  33.         if(this.index>=this.text.length)
  34.         {
  35.             this.index = 0;
  36.             this.othercolor = !this.othercolor;
  37.         }
  38.        
  39.         oc = this.othercolor;
  40.         txt = "<span class='newsticker"+(oc?"2":"1")+"'>"+this.text.substring(this.index)+"</span>";
  41.    
  42.         for(i=1;i<this.count;i++)
  43.         {
  44.             oc = !oc;
  45.             txt += "<span class='newsticker"+(oc?"2":"1")+"'>"+this.text+"</span>";
  46.  
  47.         }
  48.         oc = !oc;
  49.         txt += "<span class='newsticker"+(oc?"2":"1")+"'>"+this.text.substring(0,this.index)+"</span>";
  50.        
  51.         this.container.innerHTML = txt;
  52.     }
  53.     window.setTimeout("newsticker.loop()","75");   
  54. }
  55.  
  56. NewsTicker.prototype.updateCheck = function()
  57. {
  58.     /** update routine **/
  59.     //window.setTimeout("newsticker.updateCheck()","60000");
  60. }
  61.  
  62. NewsTicker.prototype.start = function()
  63. {
  64.     this.loop();
  65.     this.updateCheck();
  66. }
  67.  
  68. window.newsticker = new NewsTicker();
  69. window.newsticker.start();
Advertisement
Add Comment
Please, Sign In to add comment