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

286
Views
addEventListener touchstart and touchend not working

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;       
}
about 4 years ago · Santiago Trujillo
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!