Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
How to smoothly move an object on a touchscreen display?

The problem is my code works for computer browsers, but doesn't work for mobile browsers. My task is to hold my finger on an object, start moving my finger across the touch screen and see the smooth movement of the object on the screen, and when I release my finger, I can move some more objects, and not the same one. All events must take place in mobile browsers. I tried to use events such as touchmove, touchstart, but they don't work at all, since they are designed to work with touch displays.

<!DOCTYPE html>
<html>
 <head>
   <title>LogicBuilder</title>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <style>
*{
  position: absolute;
}

#ball{

  width:100px;
  height:100px;
  border-radius: 50%;
  background-color: blue;
  text-align: center;
  position:absolute;
  left:300px;
  top:300px;
}

  </style>
  
 </head>

 <body>

  
  <div id="ball"></div>

 </body> 
<script>
  ball.addEventListener('mousemove', function(event) { // (1) отследить нажатие

moveAt(event.pageX, event.pageY);

function moveAt(pageX, pageY) {
  ball.style.left = pageX - ball.offsetWidth / 2 + 'px';
  ball.style.top = pageY - ball.offsetHeight / 2 + 'px';
}

function onMouseMove(event) {
  moveAt(event.pageX, event.pageY);
}


document.addEventListener('touchmove', onMouseMove);

document.onmouseup = function() {
  document.removeEventListener('mousemove', onMouseMove);
  ball.onmouseup = null;
};


});

</script>
</html>

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda