87,910
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// 鼠标移动后开始计时,5秒后执行action
var timer = 5;
var isExecuting = false;
document.addEventListener( "mousemove", function () {
if ( isExecuting ) return;
isExecuting = true;
setTimeout( action, timer * 1000 );
} );
function action(){
alert("do action()!");
}
</script>
</body>
</html>
setTimeout(function(){
document.addEventListener('mousemove',function(){
action();
})
},5000)
function action(){
//
}
var user=false;
var time=false;
document.addEventListener('mousemove',function(){
user=true;
action();
})
setTimeout(function(){
time=true;
action();
},5000)
function action(){
if(user && time){
//代码
}
}