@WebDev921

Как остановить выполнение ивента в js?

Каким способом можно остановить выполнение ивента "wheel", например в другой функции
document.querySelector('block-wrapper').addEventListener('wheel', event => {
    event.preventDefault()
    this.mouseWheel(event)
})


mouseWheel(event) {
    horizontTransform -= event.deltaY
    document.querySelector('block').style.transform = `translateX(${horizontTransform}px)`
}
  • Вопрос задан
  • 146 просмотров
Решения вопроса 1
@citizen55
// Add an abortable event listener to table
const controller = new AbortController();
const el = document.getElementById("outside");
el.addEventListener("click", modifyText, { signal: controller.signal } );

// Function to change the content of t2
function modifyText() {
  const t2 = document.getElementById("t2");
  if (t2.firstChild.nodeValue == "three") {
    t2.firstChild.nodeValue = "two";
  } else {
    t2.firstChild.nodeValue = "three";
    controller.abort(); // remove listener after value reaches "three"
  }
}


так пойдет?
взято здесь https://developer.mozilla.org/en-US/docs/Web/API/E...
посмотрите поддержку браузерами https://caniuse.com/?search=AbortController
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы