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

200
Visualizações
How to scroll down by touch without triggering other touch event?

I have movable block, which moves on x-axis, but i want to scroll page down by touch without moving movable block. If i move block to the left or to the right, it should be moved. But if i use touch to scroll page, movable block shouldn't be moved.

HTML:

<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Swipe</title>
</head>
<body>
  <h1 class='h1'>OPEN MOBILE VIEW IN DEVTOOLS</h1>
  <div class="container">
    <div class='movable-block'>
      <span class="movable-block__title">Movable block</span>
      <div class="movable-block__line"></div>
    </div>
  </div>
</body>
</html>

JS:

const container = document.getElementsByClassName('container')[0];
const movableBlock = document.getElementsByClassName('movable-block')[0];
container.addEventListener('touchstart', () => {
    container.addEventListener('touchmove', (event) => {
    movableBlock.style.left = event.touches[0].pageX - movableBlock.offsetWidth / 2 + 'px';
  });
}); 

Example on jsfiddle (open mobile view in devtools): https://jsfiddle.net/flarrow/k3m8dy0b/93/

about 4 years ago · Santiago Gelvez
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