最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js實(shí)現(xiàn)網(wǎng)頁同時(shí)進(jìn)行多個(gè)倒計(jì)時(shí)功能

 更新時(shí)間:2019年02月25日 10:42:23   作者:qingqian2  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)網(wǎng)頁同時(shí)進(jìn)行多個(gè)倒計(jì)時(shí)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)網(wǎng)頁同時(shí)進(jìn)行多個(gè)倒計(jì)時(shí)的具體代碼,供大家參考,具體內(nèi)容如下

創(chuàng)建一個(gè)時(shí)間類Timer.

每個(gè)商品的倒計(jì)時(shí)生成一個(gè)實(shí)例:var time = new Timer();

/**
*startime 應(yīng)該是毫秒數(shù)
*/
 
var Alarm = function (startime, endtime, countFunc, endFunc) {
    this.time = Math.floor((endtime - startime) / 1000); //時(shí)間
    this.countFunc = countFunc; //計(jì)時(shí)函數(shù)
    this.endFunc = endFunc; //結(jié)束函數(shù)
    this.flag = 't' + Date.parse(new Date()); //
  };
Alarm.prototype.start = function () {
  var self = this;
 
  self.flag = setInterval(function () {
    if (self.time < 0) {
      clearInterval(self.flag);
      self.endFunc();
      console.log('計(jì)時(shí)結(jié)束');
    } else {
      var minute, hour, day, second;
      day = Math.floor(self.time / 60 / 60 / 24) < 10 ? '0' + Math.floor(self.time / 60 / 60 / 24) : Math.floor(self.time / 60 / 60 / 24);
      hour = Math.floor(self.time / 60 / 60 % 24) < 10 ? '0' + Math.floor(self.time / 60 / 60 % 24) : Math.floor(self.time / 60 / 60 % 24);
      minute = Math.floor(self.time / 60 % 60) < 10 ? '0' + Math.floor(self.time / 60 % 60) : Math.floor(self.time / 60 % 60);
      second = Math.floor(self.time % 60) < 10 ? '0' + Math.floor(self.time % 60) : Math.floor(self.time % 60);
      //倒計(jì)時(shí)執(zhí)行函數(shù)
      self.countFunc(second, minute, hour, day);
      self.time--;
    }
  }, 1000);
}

如果調(diào)用:

var time1 = new Alarm(startime, endtime, countFunc, endFunc);
time1.start();
 
var time2 = new Alarm(startime, endtime, countFunc, endFunc);
time2.start();
...

調(diào)用示例:

var countTime = function () {
  var eles = $('.count_time'),
    len = eles.length;
  for (; len > 0; len--) {
    var ele = eles.eq(len - 1);
    (function (ele) {
      startTime = new Date(ele.attr('data-start-time')).getTime(),
          endTime = new Date(ele.attr('data-end-time')).getTime(),
          alarm = new Alarm(startTime, endTime, function (second, minute, hour, day) { //計(jì)時(shí)鐘
            ele.text(hour + ':' + minute + ':' + second);
          }, function () { //倒計(jì)時(shí)結(jié)束
            ele.text('00:00:00');
            window.location.reload();
          });
      alarm.start();
    })(ele);
  }
};
countTime();

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

遵义县| 昌都县| 凌海市| 朝阳市| 商丘市| 富锦市| 郑州市| 临洮县| 阳城县| 二手房| 峨边| 长乐市| 泌阳县| 阿城市| 彝良县| 东辽县| 临清市| 甘孜县| 阳信县| 调兵山市| 正定县| 兰溪市| 班戈县| 临海市| 江山市| 兴安县| 龙南县| 曲阳县| 商城县| 安西县| 平泉县| 正镶白旗| 灵丘县| 郧西县| 临西县| 石城县| 蒙山县| 镇巴县| 临沂市| 大石桥市| 巴林左旗|