Script is functioning as expected on a PC, but nothing happens in the mobile version.
How do I get it working so that a swipe left or right moves the div accordinly?
More stuff here so I can actually submit all the code.
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;
}