0

У меня есть сценарий при использовании библиотеки typed.js . Я пытаюсь вывести 3 строки + 1 последнюю. Код работает, выводя 2 строки + 1 последнюю. При попытке исправить это код зависает без отправки сообщения об ошибке.

Эта версия кода работает без ошибок. Выводит 2 линии + 1. out

  const lineNumber = app.id !== 2 ? ++app.id : (app.id += 2);

  setTimeout(() => {
    const typed = new Typed(`#line${lineNumber}`, {
      strings: text,
      typeSpeed: speed,
      onComplete: callback,
    });
  }, timeout);
};

$.getJSON(ipgeolocation, (data) => {
  writeLine(["line1"], 30, () => {
    if (app.skippedIntro) return;

    clearCursor();

    const usernames = ['user', 'dude'];

    const ip = data.ip ? data.ip : usernames[Math.floor(Math.random() * usernames.length)];
    const country = data.country_name ? data.country_name : 'your country';

    writeLine([`line2`], 30, 500, () => {
      if (app.skippedIntro) return;
      
      clearCursor();
        
      writeLine([`start`], 120, 500, () => {
        timeouts.push(
          setTimeout(() => {
            if (app.skippedIntro) return;

            clearCursor();

            setTimeout(() => {
              skipIntro();
            }, 500);
          }, 1000)
        );
      });
    });
  });
});

Эта версия кода не работает. Согласно идее, он должен выводить 3 строки + 1.out

  const lineNumber = app.id !== 2 ? ++app.id : (app.id += 2);

  setTimeout(() => {
    const typed = new Typed(`#line${lineNumber}`, {
      strings: text,
      typeSpeed: speed,
      onComplete: callback,
    });
  }, timeout);
};

$.getJSON(ipgeolocation, (data) => {
  writeLine(["line1"], 30, () => {
    if (app.skippedIntro) return;

    clearCursor();

    const usernames = ['user', 'dude'];

    const ip = data.ip ? data.ip : usernames[Math.floor(Math.random() * usernames.length)];
    const country = data.country_name ? data.country_name : 'your country';

    writeLine([`line2`], 30, 500, () => {
      if (app.skippedIntro) return;
      
      clearCursor();

      writeLine([`line3`], 30, 500, () => {
        if (app.skippedIntro) return;
        
        clearCursor();
        
        writeLine([`start`], 120, 500, () => {
        timeouts.push(
          setTimeout(() => {
            if (app.skippedIntro) return;

            clearCursor();

            setTimeout(() => {
              skipIntro();
            }, 500);
          }, 1000)
        );
        });
      });
    });
  });
});

1 ответ 1

0

Так как нужно перенести с 3 строки на 5, нужно было исправить значения app.id.

Решение:

 const lineNumber = app.id !== 3 ? ++app.id : (app.id += 2);

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.