How to detect idle time in JavaScript elegantly?

前端 未结 30 2414
别跟我提以往
别跟我提以往 2020-11-21 11:51

Is it possible to detect \"idle\" time in JavaScript?
My primary use case probably would be to pre-fetch or preload content.

Idle time:

30条回答
  •  梦毁少年i
    2020-11-21 12:55

    You can do it more elegantly with underscore and jquery-

    $('body').on("click mousemove keyup", _.debounce(function(){
        // do preload here
    }, 1200000)) // 20 minutes debounce
    

提交回复
热议问题