The countdown is suspended when the IOS WeChat background is running.

Source: Internet
Author: User

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)                            }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.