How do you learn to make these things?
How it works: they bind the getPosition function the mousedown event, which in turn starts the appropriate draw function. They have 19 frames, each of which has its own draw function that draws rectangles. Every 1000/FPS seconds, the the update and beginDraw functions are called, which are responsible for tween effect.
That's the short answer.