1

ユーザーが 5 分間非アクティブなときにポップアップを表示しようとしています。

  timeout() {
    setTimeout(() => this.openDialog(), 4000);
 }
<h2 mat-dialog-title>Alert!</h2>
<mat-dialog-content class="mat-typography">
</mat-dialog-content>
<mat-dialog-actions align="end">
  <button mat-button mat-dialog-close>Cancel</button>
  <button mat-button [mat-dialog-close]="true"cdkFocusInitial>Ok</button>
</mat-dialog-actions>

上記のコードでは、this.openDialog()2 秒後にページを開くとダイアログが表示されます。しかし、ユーザーが5分間非アクティブになったときにポップアップを表示したい.

4

2 に答える 2

2

これを試して:

let timer;

function time() {
timer = setTimeout(() => {
     console.log(5000)
}, 5000) 
}

time();

document.addEventListener('click', () => {
  clearTimeout(timer);
  time();
})
于 2018-11-01T20:11:32.837 に答える