Now I have such a problem:
对于webapp 有一个活动列表,列表里每个活动有一个倒计时,
一旦把app切入后台,js 计时器就不在生效了,导致倒计时不准确,
有想过解决方法,监听visibilitychange事件,观察document.visibilityState
I want to make a component or function that can solve all the countdown problems on the page,
but my idea is stuck. I wonder if the experts have any good ideas, solutions, or information?
Thanks!
Question supplement:
When I was debugging the timer on my mobile phone, I opened the same page in WeChat and the default browser of the mobile phone,
switched to the background respectively, and found that the page timer in WeChat was still running, and the default browser was The server has stopped running.
When printing in the default browser of the mobile phone, document.visibilityState is undefined, but if the webpage is run in WeChat, it can be printed normally.
Excuse me why? Has WeChat done anything to deal with it?
Compare with the system time of the mobile phone;
If you are still unsure, compare with the system time of the backend when the app is opened.