0
document.getElementById("visually").onclick = function () {
  document.getElementById("die").classList.add("block__active");
  document.getElementById("die").classList.remove("block__hidden");
};

Есть часть кода. Нужно, что б после клика, она срабатывала через 2 секунды.

Попробовал таким макаром, но видимо, что-то упустил:

function f() {
  setTimeout(function () {
    document.getElementById("visually").onclick = function () {
      document.getElementById("die").classList.add("block__active");
      document.getElementById("die").classList.remove("block__hidden");
    };
  }, 2000);
}

Прошу помощи.

1 ответ 1

1

Немного не так.

Вы определили функцию, но не вызвали её:

  const someMethod = function () {
    document.getElementById("die").classList.add("block__active");
    document.getElementById("die").classList.remove("block__hidden");
  }

  const f = function () {
      setTimeout( someMethod, 2000);
  }

  document.getElementById("visually").onclick = f;

Думаю, как-то так применительно к вашему коду.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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