Skip to content
Ryc O'Chet edited this page Jun 3, 2018 · 2 revisions
- NOTE: This documentation is for Velocity v2.

Option: Begin

Pass begin a function to be triggered prior to the start of the animation (see VelocityCallback in index.d.ts).

As with complete, the begin callback is executed once per call, even if multiple elements are being animated. Further, if a call is looped, the begin callback only fires once - at the beginning of the first loop alternation.

The callback is passed the element array as both its context and its first argument. To access these elements individually, you must iterate over the array. This array also has .velocity(...) available on it for addressing directly.

The second argument is passed an AnimationCall object (see velocity.d.ts in the source for full details). The most useful member of this is the .element member, which will be the first element to animate from the element array (not necessarily the first entry in the array).

element.velocity({
    opacity: 0
}, {
    /* Log all the animated elements. */
    begin: function(elements, activeCall) {
        console.log("Animating " + elements.length + " elements:", elements);
    }
});