El script funciona como se esperaba en una PC, pero no sucede nada en la versión móvil.
¿Cómo puedo hacer que funcione para que un deslizamiento hacia la izquierda o hacia la derecha mueva el div en consecuencia?
Más cosas aquí para que pueda enviar todo el código.
document.addEventListener("touchstart", touchStart, false); document.addEventListener("touchend", touchEnd, false); document.addEventListener("mousedown", touchStart, false); document.addEventListener("mouseup", touchEnd, false); var xDown = null; var yDown = null; function touchStart(event) { xDown = event.clientX; yDown = event.clientY; } function touchEnd(event) { var currentPlayerPosition = parseInt(window.getComputedStyle(playerModel, null).getPropertyValue('left')); if ( ! xDown || ! yDown ) { return; } var xUp = event.clientX; var yUp = event.clientY; var xDiff = xDown - xUp; var yDiff = yDown - yUp; if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) { if ( xDiff > 0 ) { if(currentPlayerPosition <= "25") { return; } document.getElementById("playerModel").style.left = currentPlayerPosition - 25 + "px"; } else { if(currentPlayerPosition >= "230") { return; } document.getElementById("playerModel").style.left = currentPlayerPosition + 25 + "px"; } } else { if ( yDiff > 0 ) { } else { } } xDown = null; yDown = null; }