zoukankan      html  css  js  c++  java
  • ionic3+angular 倒计时效果

    // 声明变量
      applicationInterval: any; // 定时器
      nextBtnText: String;
      nextBtnBool: Boolean;
      // 使用定时器,每秒执行一次
      ionViewDidEnter() {
        let that = this;
        let applicationPageOpenData: number = parseInt(((new Date().getTime() / 1000) + 120).toString()); //120是设置的秒数
        let nowDte: number;
        this.nextBtnText = "30秒后方可点击"; // 按钮文本
        this.nextBtnBool = false; // 按钮是否可点击标识
        this.applicationInterval = setInterval(() => {
          nowDte = parseInt((new Date().getTime() / 1000).toString());
          console.log(nowDte);
          let receiveDate = applicationPageOpenData - nowDte;
          if (receiveDate > 0) {
            let tss = this.s_to_hs(receiveDate);
            that.nextBtnText = tss + "秒后方可点击";
            
            console.log(this.s_to_hs(receiveDate));
          } else {
            that.nextBtnText = "下一步";
            that.nextBtnBool = true;
            // 停止定时器
            clearInterval(that.applicationInterval);
          }
        }, 1000);
      }
      s_to_hs(s){
        //计算分钟
        //算法:将秒数除以60,然后下舍入,既得到分钟数
        var h;
        h  =   Math.floor(s/60);
        //计算秒
        //算法:取得秒%60的余数,既得到秒数
        s  =   s%60;
        //将变量转换为字符串
        h    +=    '';
        s    +=    '';
        //如果只有一位数,前面增加一个0
        h  =   (h.length==1)?'0'+h:h;
        s  =   (s.length==1)?'0'+s:s;
        console.log(h+':'+s);
        return h+':'+s;
      }
  • 相关阅读:
    解决运行docker命令要用sudo的问题
    python3 http.server 本地服务支持跨域
    Linux 命令速记本
    截取某段时间内的日志
    centos7 安装postgresql10
    centos 7 安装 mail
    centos7 mail
    centos7 mysql 5.7 官网下载tar安装
    修改storm ui 默认端口
    redis-trib构建集群
  • 原文地址:https://www.cnblogs.com/opcec/p/9876937.html
Copyright © 2011-2022 走看看