JS
https://www.brcline.com/blog/detecting-inactivity-in-javascript
Angular: app.component
@HostListener('mousemove') onMove() {
this.resetTimer();
}
@HostListener('mousedown') onDown() {
this.resetTimer();
}
@HostListener('keypress') onPress() {
this.resetTimer();
}
@HostListener('touchmove') onTouchMove() {
this.resetTimer();
}
ngAfterViewInit() {
this.startInactiveTimer();
}
startTimer(): void {
this.timeoutId = setTimeout(
() => {
// DO something
this.startTimer();
}
, this.timeoutValue);
}
resetTimer(): void {
clearTimeout(this.timeoutId)
this.startTimer();
}
No comments:
Post a Comment