Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.
X

Typewriter Style for Website News

I am currently working on a client's website and he specifically asked for typewritter style for his important news. It really took me time to get something that worked because of several JQuery plugins I used for different javascript actions on the website but I finally got one working perfectly. Below is the javascript code. Place it in your HTML head tag.



var text="Lorem ipsum dolor sit amet, consectetur adipisicing elit.";
var delay=50;
var currentChar=1;
var destination="[not defined]";
function typewriter(){ 
  if (document.getElementById) {
         var dest=document.getElementById(destination);
      if (dest){
         dest.innerHTML=text.substr(0, currentChar);
         currentChar++
 if (currentChar>text.length){
        currentChar=1;
        setTimeout('typewriter()', 5000);
      }
      else
      {
        setTimeout('typewriter()', delay);
      }
    }
  }
}
function startTyping(textParam, delayParam, destinationParam){
  text=textParam;
  delay=delayParam;
  currentChar=1;
  destination=destinationParam;
  typewriter();
}


Add below line of code to where you want to display the effect in your HTML:


Latest:
...
 
...

Place below line of code before the end of your </body> tag

startTyping(text, 50, "textDestination");

You can download this html demo below to see how it works.

This works for me. Please if you have any challenges with it never hestitate to contact me.

 


comments powered by Disqus