Last active
December 15, 2015 06:09
-
-
Save kenjiSpecial/5214439 to your computer and use it in GitHub Desktop.
- mouse event on PC and touch event on Mobile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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