Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
¿Cómo desplazarse hacia abajo al tocar sin activar otro evento táctil?

Tengo un bloque móvil, que se mueve en el eje x, pero quiero desplazarme hacia abajo con el tacto sin mover el bloque móvil. Si muevo el bloque hacia la izquierda o hacia la derecha, debe moverse. Pero si uso el toque para desplazarme por la página, el bloque móvil no debería moverse.

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'; }); });

Ejemplo en jsfiddle (vista móvil abierta en devtools): https://jsfiddle.net/farrow/k3m8dy0b/93/

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!