Giter Club home page Giter Club logo

alm-timer.js's Introduction

Timer

特定の処理を一定間隔で指定回数だけ繰り返すことができるJavaScriptライブラリです。

✨ 主な特徴

  • 遅延時間をミリ秒単位で指定可能(ブラウザ依存の誤差あり)
  • 無制限の繰り返し回数を指定可能
  • 一時停止と再開が可能
  • イベント駆動

🚀 導入

以下のコードをによって読み込みます。

<script src="https://cdn.jsdelivr.net/npm/alm-timer.js/dist/index.min.js"></script>

✍ 使い方

// 5秒おきに10回繰り返すタイマーを作成する
const timer = new alm_timer.Timer(5000, 10);

// 繰り返すごとに呼ばれるイベントハンドラ
timer.addEventListener('count', (event) => {
    console.log(`${event.detail.elapsedCount}回目`);
});

// 指定回数繰り返したら呼ばれるイベントハンドラ
timer.addEventListener('complete', (event) => {
    console.log('完了');
});

// タイマーを開始
timer.start();

主な機能

// delay: ミリ秒(デフォルト 1000)
// repeatCount: 繰り返し回数(デフォルト 0 = 無制限)
timer = new alm_timer.Timer(delay, repeatCount);
// タイマーを実行または再開します
timer.start();
// タイマーを一時停止します
timer.stop();
// タイマーを実行前の状態に戻して停止します
timer.reset();
// タイマーを実行前の状態に戻して開始します
timer.restart();

ドキュメント

APIリファレンス

alm-timer.js's People

Contributors

alumican avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.