内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

微信公眾號(hào)中如何實(shí)現(xiàn)倒計(jì)時(shí)的一個(gè)功能-創(chuàng)新互聯(lián)

小編給大家分享一下微信公眾號(hào)中如何實(shí)現(xiàn)倒計(jì)時(shí)的一個(gè)功能,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

站在用戶(hù)的角度思考問(wèn)題,與客戶(hù)深入溝通,找到綏德網(wǎng)站設(shè)計(jì)與綏德網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶(hù)體驗(yàn)好的作品,建站類(lèi)型包括:成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請(qǐng)、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋綏德地區(qū)。

代碼如下:

let interval = setInterval(() => {
            let {staticTime} = this.state;
            staticTime = staticTime - 1;
            if (staticTime <= 0) {
                clearInterval(interval);
                this.setState({
                    tip:'支付超時(shí)',
                    staticTime:0
                });
                return;
            }
            let minutes = parseInt(staticTime/60);
            let Seconds = staticTime%60;
            let tip = '訂單已提交,請(qǐng)?jiān)?#39;+minutes+'分'+Seconds+'秒內(nèi)完成支付';
            this.setState({
                tip:tip,
                staticTime:staticTime 
            });
        }, 1000);
后來(lái)測(cè)試發(fā)現(xiàn)鎖屏或者把頁(yè)面留在后臺(tái),計(jì)算就不對(duì),于是把代碼進(jìn)行了如下改造。



  let interval = setInterval(() => {
            let {backGroundTime, staticTime} = this.state;
            this.setState({
                backGroundTime:0
            });
            staticTime = staticTime - backGroundTime - 1; 
            if (staticTime <= 0) {
                clearInterval(interval);
                this.setState({
                    tip:'支付超時(shí)',
                    staticTime:0,
                });
                return;
            }
            let minutes = parseInt(staticTime/60);
            let Seconds = staticTime%60;
            let tip = '訂單已提交,請(qǐng)?jiān)?#39;+minutes+'分'+Seconds+'秒內(nèi)完成支付';
            this.setState({
                tip:tip,
                staticTime:staticTime,
            });
        }, 1000);
        this.listenPageShowHideHandle();
    
     //計(jì)算頁(yè)面在后臺(tái)的時(shí)間

listenPageShowHideHandle = () =>{

let {backGroundTime} = this.state;
let start, end;
let self = this;
document.addEventListener("visibilitychange", function() {
    if(document.visibilityState == 'hidden'){
        start = new Date().getTime();
    }else if(document.visibilityState == 'visible'){
        end = new Date().getTime();
        backGroundTime = Math.floor((end - start)/1000);
        self.setState({backGroundTime});
        console.log('時(shí)間差:', backGroundTime);
    }
    console.log( document.visibilityState );
});

}

改造之后發(fā)先問(wèn)題依然存在。原因是:
You cannot continue to run javascript while the iPhone is sleeping using setTimeout(), however.When the phone is put to sleep, Safari will kill any running javascript processes using setTimeout(). Check out this answer here for some reasons why this is done.

**解決方案:**
訂單生成的時(shí)候我們記錄下這個(gè)時(shí)間為A, 時(shí)間間隔為B(3分鐘內(nèi)需要付款,B為3*60*1000),C為現(xiàn)在的時(shí)間。我們使用setInterval 每個(gè)1秒讀取一下時(shí)間。那么倒計(jì)時(shí)時(shí)間 == A+B-C,代碼如下

 let interval = setInterval(()=>{
        let {orderTime, staticTime} = this.state;
        let nowTime = Date.now();
        let sub = Math.floor((orderTime + staticTime - nowTime)/1000);
        console.log('sub',sub);
        if(sub<=0){
            clearInterval(interval);
            this.setState({
                tip:'支付超時(shí)',
                isFalse:true
            });
            return;
        }
        let minutes = parseInt(sub/60);
        let Seconds = sub%60;
        let tip = '訂單已提交,請(qǐng)?jiān)?#39;+minutes+'分'+Seconds+'秒內(nèi)完成支付';
        console.log(tip);
        this.setState({
            tip:tip,
            isFalse:false
        });
    },1000);

以上是“微信公眾號(hào)中如何實(shí)現(xiàn)倒計(jì)時(shí)的一個(gè)功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

新聞名稱(chēng):微信公眾號(hào)中如何實(shí)現(xiàn)倒計(jì)時(shí)的一個(gè)功能-創(chuàng)新互聯(lián)
本文鏈接:http://m.rwnh.cn/article42/gghhc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、定制網(wǎng)站Google、搜索引擎優(yōu)化云服務(wù)器、網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)
泉州市| 江永县| 平果县| 巴里| 商南县| 中牟县| 潮安县| 呼图壁县| 永兴县| 新巴尔虎右旗| 古丈县| 五大连池市| 修武县| 密山市| 苏州市| 甘德县| 潢川县| 安丘市| 鹿邑县| 呼和浩特市| 威远县| 个旧市| 宽甸| 富平县| 龙山县| 泰和县| 新化县| 措美县| 张北县| 图木舒克市| 织金县| 平湖市| 原平市| 株洲县| 麦盖提县| 丹阳市| 永德县| 石渠县| 嘉祥县| 黔西| 衢州市|