js轻量级支持自定义的定时器倒计时插件

所属分类: 网页特效-日期时间    2023-11-25 11:49:45

js轻量级支持自定义的定时器倒计时插件 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

js轻量级支持自定义的定时器倒计时插件(共3个文件)

    • index.html

使用方法

var pomodoroClock = {
  // set variables
  started: false,
  minutes: 0,
  seconds: 0,
  sessionLength: 25,
  sessionDOM: null,
  breakLength: 5,
  breakDOM: null,
  fillerHeight: 0,
  fillerIncrement: 0,
  interval: null,
  minutesDom: null,
  secondsDom: null,
  fillDom: null,
  runs: 1,
  startAudio: new Audio(
    "https://jpk-image-hosting.s3.amazonaws.com/pomodoro-app/audio/start.mp3"
  ),
  endAudio: new Audio(
    "https://jpk-image-hosting.s3.amazonaws.com/pomodoro-app/audio/end.mp3"
  ),

  // initialize variables, set event listeners, start interval counter function.
  init: function() {
    var self = this;

    this.minutesDom = document.querySelector("#minutes");
    this.secondsDom = document.querySelector("#seconds");
    this.fillDom = document.querySelector("#filler");
    this.sessionDOM = document.querySelector("#session-time");
    this.breakDOM = document.querySelector("#break-time");
    this.interval = setInterval(function() {
      self.intervalFunction.apply(self);
    }, 1000);

    document.querySelector("#start").addEventListener("click", function() {
      self.startCount.apply(self);
    });
    document.querySelector("#stop").addEventListener("click", function() {
      self.stopCount.apply(self);
    });
    document.querySelectorAll(".time-adjust").forEach(function(e) {
      e.addEventListener("click", function() {
        if (this.id === "sesh-plus") {
          self.sessionLength++;
        }
        if (this.id === "sesh-minus") {
          self.sessionLength--;
        }
        if (this.id === "break-minus") {
          self.breakLength--;
        }
        if (this.id === "break-plus") {
          self.breakLength++;
        }
        self.adjustValue.apply(self);
      });
    });
  },

  // functions for our program
  resetVariables: function(mins, secs, started) {
    this.minutes = mins;
    this.seconds = secs;
    this.started = started;
    this.fillerIncrement = 200 / (this.minutes * 60);
    this.fillerHeight = 0;
    this.updateUI();
  },

  startCount: function() {
    this.resetVariables(this.sessionLength, this.seconds, true);
    this.startAudio.play();
  },

  stopCount: function() {
    this.resetVariables(0, 0, false);
    this.updateUI();
  },
// for the timer. runs every second
  intervalFunction: function() {
    if (!this.started) return false;
    if (this.seconds == 0) {
      if (this.minutes == 0) {
        this.timerDone();
        return;
      }
      this.seconds = 59;
      this.minutes--;
    } else {
      this.seconds--;
    }
    this.updateUI();
  },

  numberFormat: function(num) {
    if (num < 10) {
      return "0" + parseInt(num, 10);
    } else return num;
  },

  timerDone: function() {
    this.runs++;
    this.endAudio.play();
    if (this.runs === 2 || this.runs === 4) {
      this.resetVariables(this.breakLength, 0, true);
    } else if (this.runs === 3 || this.runs === 5) {
      this.resetVariables(this.sessionLength, 0, true);
    } else {
      this.resetVariables(this.breakLength, 0, false);
    }

    //  console.log(this.runs);
  },

  updateUI: function() {
    this.minutesDom.innerHTML = this.numberFormat(this.minutes);
    this.secondsDom.innerHTML = this.numberFormat(this.seconds);
    this.sessionDOM.innerHTML = this.sessionLength + " min";
    this.breakDOM.innerHTML = this.breakLength + " min";
    this.fillerHeight += this.fillerIncrement;
    if (this.started == true) {
      this.fillDom.style.height = this.fillerHeight + "px";
    } else {
      this.fillDom.style.height = 0 + "px";
    }
  },

  adjustValue: function() {
    if (!this.sessionLength > 0) {
      this.sessionLength = 1;
    }
    if (!this.breakLength > 0) {
      this.breakLength = 1;
    } else {
      this.updateUI();
    }

    // console.log(this.sessionLength);
  }
};

window.onload = function() {
  pomodoroClock.init();
};

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 日期时间

jquery响应式标尺刻度时间选择器插件

一款横向标尺状时间刻度轴,可使用鼠标点选时间点,带callback回调!
  日期时间
 7293  0

jquery轻量级显示今天的日期插件

一款轻量级显示今日日期插件,可自定义显示日期+星期。
  日期时间
 7222  0

jquery时光隧道动画显示当前时间特效

一款动画特效显示当前时间效果,基于canvas画布实现,鼠标单击切换显示自定义文字,犹如圆形转动的时光机器,每一秒钟都闪动一下。
  日期时间
 767  0

jquery轻量级多语言左右切换日历插件

一款多语言日历插件,带显示星期几、月份、当前日期高亮,支持多语言自定义设置,超实用。
  日期时间
 3293  0

评论数(1) 回复有机会获得K币 用户协议

    jq小菜鸡0
    2023-12-08 13:29:42
    可以自己设置的倒计时,留个记号先
    回复
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论