How to detect idle time in JavaScript elegantly?

前端 未结 30 2381
别跟我提以往
别跟我提以往 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条回答
  •  鱼传尺愫
    2020-11-21 12:58

    Just a few thoughts, an avenue or two to explore.

    Is it possible to have a function run every 10 seconds, and have that check a "counter" variable? If that's possible, you can have an on mouseover for the page, can you not? If so, use the mouseover event to reset the "counter" variable. If your function is called, and the counter is above the range that you pre-determine, then do your action.

    Again, just some thoughts... Hope it helps.

提交回复
热议问题