Skip to content

Instantly share code, notes, and snippets.

@kenjiSpecial
Last active December 15, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kenjiSpecial/5214439 to your computer and use it in GitHub Desktop.
Save kenjiSpecial/5214439 to your computer and use it in GitHub Desktop.
- mouse event on PC and touch event on Mobile.
var mobileStatus;
var agent = navigator.userAgent;
// check whether the device is mobile or not.
if(agent.search(/iPhone/) != -1 || agent.search(/iPad/) != -1 || agent.search(/iPod/) != -1 || agent.search(/Android/) != -1){
mobileStatus = true;
}else{
mobileStatus = false;
}
if(mobileStatus){
document.addEventListener("touchstart", touch_start);
document.addEventListener("touchmove", touch_move);
document.addEventListener("touchend", touch_end);
}else{
document.addEventListener("mousedown", mouse_down);
document.addEventListener("mousemove", mouse_move);
document.addEventListener("mouseup", mouse_up);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment