A Raphael-powered metronome
JavaScript HTML
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.



A Raphael-powered metronome


RaphaelJs jQuery (for demo only)


Include the metronome.js script in your page


You initialize the metronome with a few parameters to set the size and angle of the animation. You can also attach custom functions to the tick event and the event that fires on the final tick. In the above example, I attach two functions that write updates to the screen.

function tick(t) {
    $("<div />").html(t%2 === 1 ? "Tick":"Tock").appendTo(".status");

function done() {
    $("<div />").html("Done!").appendTo(".status");

var m = metronome({
    len: 200,
    angle: 20,
    paper: "metronome_container",
    tick: tick,
    complete: done,
    path: ""

These are not actual Javascript events, though they probably should be.

The metronome has two functions, .start() and .stop(). The first takes two arguments, a tempo (expressed as beats per minute, like your piano teacher taught you) and a number of ticks:

m.start(120, 50);

You can interrupt the execution with:


At fast tempos, the weight occasionally gets disconnected from the metronome's arm. I addressed this issue with Raphael's .animateWith() function [on Stack Overflow][2], but I'm not convinced the accepted answer is complete.

You can invoke the .start() and .stop() functions any way you like, but as a shortcut you can create a pair of inputs for the tempo and tick number and create a start/stop button with one function: