Socket
Socket
Sign inDemoInstall

countdown-pro

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    countdown-pro

A simple countdown.


Version published
Maintainers
1
Install size
42.8 kB
Created

Readme

Source

CountDown

npm npm GitHub

一个简单的倒计时。

查看示例

使用

npmyarn 安装

npm install countdown-pro
yarn add countdown-pro

浏览器引入

在浏览器中使用 script 标签直接引入文件,并使用全局变量 CountDown

  • 该仓库的 dist 目录下提供了 countdown.umd.js 以及 countdown.umd.min.js
  • npm 包的 countdown-pro/dist 目录下也提供了 countdown.umd.js 以及 countdown.umd.min.js
  • 你也可以通过 UNPKG 进行下载。

示例

import CountDown from 'countdown-pro';

const countdown = new CountDown({
  time: 60 * 1000,
  interval: 1000,
  onChange: (time) => {
    console.log(time);
  },
  onEnd: () => {
    console.log('结束');
  }
});

countdown.start();

配置项

参数说明类型必填默认值
time倒计时,单位毫秒numberY0
interval时间间隔,单位毫秒number-1000
onChange每次时间间隔时触发(currentTime) => void--
onEnd倒计时结束时触发() => void--

实例方法

方法名说明
start开始倒计时
pause暂停倒计时
reset重置倒计时

静态方法

内置一些简单日期格式方法,通过 CountDown.方法名 直接调用。

CountDown.format(timestamp, pattern='HH:mm:ss')

格式化时间,返回格式化后的时间字符串

CountDown.format(2 * 60 * 60 * 1000); // "02:00:00"
CountDown.format(2 * 60 * 60 * 1000, 'mm:ss'); // "120:00"
参数说明类型必填默认值
timestamp时间戳,单位毫秒numberY-
pattern时间格式,DD-日,HH-时,mm-分,ss-秒,SSS-毫秒string-HH:mm:ss

CountDown.padZero(num, targetLength=2)

前置补零,返回补零后的值

CountDown.padZero(2); // "02"

CountDown.parseTimeData(timestamp)

解析时间戳,返回的时间对象格式 timeData

interface TimeData {
  days: number; // 天数
  hours: number; // 小时
  minutes: number; // 分钟
  seconds: number; // 秒数
  milliseconds: number; // 毫秒
}
CountDown.parseTimeData(2 * 60 * 60 * 1000); // {days: 0, hours: 2, minutes: 0, seconds: 0, milliseconds: 0}

Keywords

FAQs

Last updated on 19 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc