Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
How to stop scrolling the page when a swipe is noticed?

I've made a game in which when i swipe on the canvas it changes directions , but on swiping down or up on the canvas the whole page scrolls , how can I avoid scrolling just on the canvas , but not outside the page?

  Area.addEventListener("touchstart", startTouch, false);
  Area.addEventListener("touchmove", moveTouch, false);

   // Swipe Up / Down / Left / Right
    var initialX = null;
      var initialY = null;
   
    function startTouch(e) {
    initialX = e.touches[0].clientX;
initialY = e.touches[0].clientY;
  };

   function moveTouch(e) {
if (initialX === null) {
  return;
}

if (initialY === null) {
  return;
}

var currentX = e.touches[0].clientX;
var currentY = e.touches[0].clientY;

var diffX = initialX - currentX;
var diffY = initialY - currentY;

if (Math.abs(diffX) > Math.abs(diffY)) {
  // sliding horizontally
  if (diffX > 0) {
    // swiped left
    console.log("swiped left");
  } else {
    // swiped right
    console.log("swiped right");
  }  
} else {
  // sliding vertically
  if (diffY > 0) {
    // swiped up
    console.log("swiped up");
  } else {
    // swiped down
    console.log("swiped down");
  }  
}

initialX = null;
initialY = null;

e.preventDefault();
 };
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda