Created
March 1, 2017 07:04
-
-
Save ksk1015/36fa95bd654af2320ea5be5593541b0f to your computer and use it in GitHub Desktop.
detect movable mouse (means a device has movable mouse pointer)
This file contains 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
(function(){ | |
// over 2 mousemove events fired in 300ms | |
var over = 2, period = 300; | |
var count = 0; | |
var timer = null; | |
var mousemove = function(evt){ | |
if ( !timer ) { | |
timer = setTimeout(function(){ | |
timer = null; | |
count = 0; | |
}, period); | |
return; | |
} | |
if ( ++count < over ) { | |
return; | |
} | |
document.removeEventListener('mousemove', mousemove); | |
window.movableMouse = true; | |
document.documentElement.classList.add('movableMouse'); | |
fireEvt(); | |
}; | |
var fireEvt = function(){ | |
var evt = document.createEvent('HTMLEvents'); | |
evt.initEvent('movableMouse', false, false); | |
document.dispatchEvent(evt); | |
}; | |
window.movableMouse = false; | |
document.addEventListener('mousemove', mousemove); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment