When the IOS background is running, the countdown is suspended.
Link: https://pan.baidu.com/s/1i7cSkqL password: g80i
I recently played an H5 Q & A game for CCTV, but encountered a terminal problem during the countdown: After the mobile phone client presses the Home Key to generate the background, IOS11 will continue to run JS for five seconds, note that it is 5 seconds, that is, when the countdown is 9, the backend is received, and the JS will start to count down from 4 after one minute. I heard that IOS6 can run for 10 minutes, IOS7 has 3 minutes, And IOS11 only has 5 seconds .... however, TM is a BUG. You have to modify it. (PS: android can run normally in 10 s, and I have never tried to run it for several seconds. Maybe this is why the Android software is too choppy ). I chose to obtain the current timestamp to solve this problem. The specific code analysis is as follows:
function Time_a() { var time = 10; $(".time").text(time); var t = setInterval(function() { if(time == 0) { clearTimeout(t); } else { time--; $(".time").text(time) } }, 1000) }
When time --; is used for countdown, there will be a countdown fault on IOS11. Therefore, I chose to use the timestamp and use the background time limit to solve the background running time limit of IOS.
function Time_b(){ var time=10; var beginTime=new Date().getTime(); $(".time-a").text(time); var t= setInterval(function(){ var newTime=new Date().getTime(); var dTime=(newTime-beginTime)/1000; dTime=parseInt(dTime); time = 10-dTime > 0 ? 10-dTime : 0; $(".time-a").text(time); },1000) }