是否可以在JavaScript中检测" 空闲 "时间?
我的主要用例可能是预取或预加载内容.
空闲时间:用户不活动或没有任何CPU使用的时间段
我需要知道REACT JS或HTML5中是否有任何API可提供在用户不活动时自动注销的功能。不必要的绑定。请告诉我我要去哪里了
import React from 'react';
import ReactDOM from 'react-dom';
import './App.css';
class Toogle extends React.Component {
constructor(props) {
super(props);
//step 1
this.handleClick = this.handleClick.bind(this);
this.startTimer=this.startTimer.bind(this)
}
handleClick() {
console.log('Button is clicked');
// clearTimeout(timeoutTimer);
startTimer() {
var timeoutTimer = setTimeout(function() {
window.location.href = '#/security/logout';
}.bind(this), 1000);
}
}
render() {
return (<div onMouseMove={this.handleClick}>Move the cursor over me</div>);
}
}
ReactDOM.render(
<Toogle />,
document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)