• Как сделать некоторый текст статическим?

    @Khalit
    function setTyper(element, words) {
    
      const LETTER_TYPE_DELAY = 75;
      const WORD_STAY_DELAY = 2000;
    
      const DIRECTION_FORWARDS = 0;
      const DIRECTION_BACKWARDS = 1;
    
      var direction = DIRECTION_FORWARDS;
      var wordIndex = 0;
      var letterIndex = 0;
    
      var wordTypeInterval;
    
      var preffix = "static-"
      
      startTyping();
    
      function startTyping() {
        wordTypeInterval = setInterval(typeLetter, LETTER_TYPE_DELAY);
      }
    
      function typeLetter() {
        const word = preffix+words[wordIndex];
    
        if (direction == DIRECTION_FORWARDS) {
          letterIndex++;
    
          if (letterIndex == word.length) {
            direction = DIRECTION_BACKWARDS;
            clearInterval(wordTypeInterval);
            setTimeout(startTyping, WORD_STAY_DELAY);
          }
    
        } else if (direction == DIRECTION_BACKWARDS) {
          letterIndex--;
    
          if (letterIndex == preffix.length) {
            nextWord();
          }
        }
    
        const textToType = word.substring(0, letterIndex);
    
        element.textContent = textToType;
      }
    
      function nextWord() {
    
        letterIndex = preffix.length;
        direction = DIRECTION_FORWARDS;
        wordIndex++;
    
        if (wordIndex == words.length) {
          wordIndex = 0;
        }
    
      }
    }
    Ответ написан
    1 комментарий