Skip to content

Instantly share code, notes, and snippets.

@motoishmz
Forked from kenjiSpecial/main.js
Last active December 15, 2015 06:19
Show Gist options
  • Save motoishmz/5215227 to your computer and use it in GitHub Desktop.
Save motoishmz/5215227 to your computer and use it in GitHub Desktop.
// to be binded.....
var fnTouchStart = function(e) { console.log("hello i am touch start"); };
var fnTouchMove = function(e) { console.log("hello i am touch move"); };
var fnTouchEnd = function(e) { console.log("hello i am touch end"); };
var fnMouseDown = function(e) { console.log("hello i am mouse down"); };
var fnMouseMove = function(e) { console.log("hello i am mouse move"); };
var fnMouseUp = function(e) { console.log("hello i am mouse up"); };
// register.....
(function()
{
var bMobileDevice;
var UA = navigator.userAgent;
// check whether the device is mobile or not....
bMobileDevice =
/iphone/i.test(UA) ||
/ipad/i.test(UA) ||
/ipod/i.test(UA) ||
/android/i.test(UA);
// bind....
if(bMobileDevice)
{
document.addEventListener("touchStart", fnTouchStart);
document.addEventListener("touchmove", fnTouchMove);
document.addEventListener("touchend", fnTouchEnd);
}
else
{
document.addEventListener("mousedown", fnMouseDown);
document.addEventListener("mousemove", fnMouseMove);
document.addEventListener("mouseup", fnMouseUp);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment