Skip to content

Instantly share code, notes, and snippets.

@jumplee
Last active November 3, 2019 03:06
Show Gist options
  • Save jumplee/52583209e3cd5c12cb2628071da83c76 to your computer and use it in GitHub Desktop.
Save jumplee/52583209e3cd5c12cb2628071da83c76 to your computer and use it in GitHub Desktop.
屏幕长时间无操作执行相应操作(回到首页等)
/**
* 屏幕长时间无操作执行相应操作(回到首页等)
* @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