Last active
November 3, 2019 03:06
-
-
Save jumplee/52583209e3cd5c12cb2628071da83c76 to your computer and use it in GitHub Desktop.
屏幕长时间无操作执行相应操作(回到首页等)
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
/** | |
* 屏幕长时间无操作执行相应操作(回到首页等) | |
* @param callback | |
* @param millisecond | |
*/ | |
function hasOperate(callback, millisecond) { | |
var timer; | |
function onEnd(){ | |
if(timer){ | |
clearTimeout(timer); | |
timer=false; | |
} | |
countTime(); | |
} | |
// 是否支持触摸 | |
if('ontouchend' in document){ | |
document.body.addEventListener('touchend', onEnd); | |
}else{ | |
document.body.addEventListener('mouseup', onEnd); | |
} | |
function countTime() { | |
timer = setTimeout(callback,millisecond) | |
} | |
// 开始计时 | |
countTime(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment