小程序,商品秒殺倒計(jì)時(shí)效果

html部分:
<text>{{daojishi_show}}</text>

js部分:
Page({

  /**
   * 頁(yè)面的初始數(shù)據(jù)
   */
  data: {
    start_time: "1560258000",
    end_time: "1560580000",
    daojishi_show:' ',
  },

  daojishi: function () {
    var timestamp = Date.parse(new Date());
    const that = this;
    timestamp = timestamp / 1000;

    var daojishi_show = this.data.daojishi_show;
    if (timestamp < that.data.start_time) {
      var daojishi = that.data.start_time - timestamp
      daojishi = daojishi
      that.data.daojishi_show = this.dateformats(daojishi, '')
      
    } else {
      var daojishi = that.data.end_time - timestamp;
      if (daojishi > 0) {
        daojishi = daojishi
        that.data.daojishi_show = this.dateformats(daojishi,'')
      } else {
        daojishi = daojishi
        that.data.daojishi_show = '已結(jié)束'
      }
    };
    this.setData({
      daojishi_show: that.data.daojishi_show
    })
  }, 
  dateformats(micro_second, title) {
    // 總秒數(shù)
    var second = Math.floor(micro_second);
    // 天數(shù)
    var day = Math.floor(second / 3600 / 24);
    // 小時(shí)
    var hr = Math.floor(second / 3600 % 24);
    var hrStr = hr.toString();
    if (hrStr.length == 1) hrStr = '0' + hrStr;

    // 分鐘
    var min = Math.floor(second / 60 % 60);
    var minStr = min.toString();
    if (minStr.length == 1) minStr = '0' + minStr;

    // 秒
    var sec = Math.floor(second % 60);
    var secStr = sec.toString();
    if (secStr.length == 1) secStr = '0' + secStr;

    if (day <= 1) {
      return title + " " + hrStr + ":" + minStr + ":" + secStr;
    } else {
      return title + " " + day + " 天 " + hrStr + ":" + minStr + ":" + secStr;
    }
  },  
  
  /**
   * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
   */
  onLoad: function (options) {
    setInterval(this.daojishi, 1000);
    var that = this;
    var temp = WxParse.wxParse('content', 'html', replyHtml0, that, 10);
  },

  /**
   * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
   */
  onShow: function () {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載
   */
  onUnload: function () {

  },

  /**
   * 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶下拉動(dòng)作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 頁(yè)面上拉觸底事件的處理函數(shù)
   */
  onReachBottom: function () {

  },

  /**
   * 用戶點(diǎn)擊右上角分享
   */
  onShareAppMessage: function () {

  }
})
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容