Giter Site home page Giter Site logo

talhaakkaya / intervalometer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fregante/intervalometer

0.0 0.0 0.0 55 KB

Call a function at every frame or every X ms. With start/stop

Home Page: https://npm.im/intervalometer

License: MIT License

JavaScript 65.52% TypeScript 34.48%

intervalometer's Introduction

intervalometer

Call a function at every frame or every X ms. With start/stop

gzipped size Travis build npm link

Usage

There are two times of intervalometers: frame-based and time-based. Both return an object with start and stop functions. You can safely call start multiple times, the callback will only run once at every interval.

frameIntervalometer(cb)

Uses requestAnimationFrame and therefore calls the provided callback at every frame. Ideal for animations

const painter = frameIntervalometer(function (millisecondsSinceLastFrame) {
	// your logic to run at every frame
});

button.onclick = function () {
	painter.start();
};

timerIntervalometer(cb, ms)

uses setTimeout and calls the callback every ms milliseconds

const poller = timerIntervalometer(pollingFunction, 100); //runs every 100 ms

startButton.onclick = function () {
	poller.start();
};
stopButton.onclick = function () {
	poller.stop();
};

Install

Pick your favorite:

<script src="dist/intervalometer.browser.js"></script>
<!-- use as intervalometer.frameIntervalometer(cb) -->
<!--     or intervalometer.timerIntervalometer(cb, ms) -->
npm install --save intervalometer
var i = require('intervalometer');
var frameIntervalometer = i.frameIntervalometer;
var timerIntervalometer = i.timerIntervalometer;
import {frameIntervalometer, timerIntervalometer} from 'intervalometer';

Dependencies

None! frameIntervalometer only works where window.requestAnimationFrame is available (yes in modern browsers; not in Node)

Related

License

MIT © Federico Brigante

intervalometer's People

Contributors

bfred-it avatar fregante avatar nickytonline 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.