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

jquery日期日历可视化序列数据热图插件

一款可视化日历热图插件,可自定义日期活动时间,点击事件可显示当前活动详情内容,类似于Github贡献图。
  日期时间
 231  

javascript基于SVG创建的复古的摇摆时钟特效代码

此特效采用了SVG、CSS和JavaScript生成的游戏时钟效果,它创建了一个带有动画指针的钟面,指针根据当前时间移动。JavaScript设置时间并触发蜂鸣声。CSS处理时钟视觉效果的动画。
  日期时间
 146  

jquery逼真精致的卡西欧在线时钟手表插件

一个逼真的卡西欧F-91w手表在线时钟特效,可根据用户偏好自动调整为亮(白天)模式或暗(夜晚)模式。该手表以12小时和24小时两种格式显示当前时间,支持鼠标点击两侧按钮调整。
  日期时间
 157  

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

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

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

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