the_usik

editing the message (animation)

Nov 24th, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const CONFIG = {
  2.         TEXT_OF_MESSAGE: "Hello, world!",
  3.         PEER_IDENTIFIER: 0,
  4.         MESSAGE_IDENTIFIER: 0, 
  5.         TIMEOUT_EDIT_MESSAGE: 1000
  6.     }
  7.     let index = 0;
  8.     let timeoutIdentifier = 0;
  9.    
  10.     let editTheMessage = (message) => {
  11.         // editing a message function
  12.         console.log(message);
  13.     }
  14.  
  15.     // stop script function
  16.     let stopScript = () => clearTimeout(timeoutIdentifier);
  17.    
  18.     let main = () => {
  19.         let currentMessage = CONFIG.TEXT_OF_MESSAGE.slice(0, index);
  20.         editTheMessage(currentMessage);
  21.            
  22.         index = (index + 1) % CONFIG.TEXT_OF_MESSAGE.length;
  23.         timeoutIdentifier = setTimeout(main, CONFIG.TIMEOUT_EDIT_MESSAGE);
  24.     }
  25.  
  26.     main();
Advertisement
Add Comment
Please, Sign In to add comment