Misfits

Twitch Chat - Typewriter Effect

Jun 10th, 2020
1,527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Please use event listeners to run functions.
  3. document.addEventListener('onLoad', function(obj) {
  4.     // obj will be empty for chat widget
  5.     // this will fire only once when the widget loads
  6. });
  7.  
  8. document.addEventListener('onEventReceived', function(obj) {
  9.     // obj will contain information about the event
  10. e++  
  11. typeEffect(e);
  12.  
  13.  
  14.  
  15.    
  16. });
  17. var speed = 100;
  18. var e = 1;
  19. function typeEffect(inp) {
  20.   var o = inp;
  21.   document.getElementById("message").id= "message"+o;
  22.     var text = $("#message"+o).text();
  23.     $("#message"+o).text('');
  24.     var i = 0;
  25.     var timer = setInterval(function() {
  26.         if(i < text.length) {
  27.             $("#message"+o).append(text.charAt(i));
  28.             i++;
  29.         }
  30.         else{
  31.             clearInterval(timer);
  32.       document.getElementById("message").id= "complete";
  33.         };
  34.   }, speed);
  35.  
  36.  
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment