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

121
Visualizações
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 à 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