2

I can check if mousedown has been triggered like so:

$(something).on("mousemove touchmove", function(e) {
    if (e.buttons == 1){
        // mouse is down
    }
})

Very simple question, how can I check if touchstart has been triggered in the above? I tried:

if (e.type === 'touchstart'){
    // touchstart has been triggered
}

This did now work at all. Can someone please provide direction as to how I can achieve this?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
almost a beginner
  • 1,622
  • 2
  • 20
  • 41

1 Answers1

1

Your if statement checking the e.type property is the correct logic to use. Your condition fails though, because you hook to mousemove and touchmove, not touchstart.

You need to either include touchstart in the event list:

$(something).on("mousemove touchmove touchstart", fn);

Or check the type property for touchmove, if that was your intent:

if (e.type === 'touchmove'){
    // touchmove has been triggered
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339