Home

Awesome

cta.js npm version

A call to animate, your action-to-effect path


cta.js or "Call to Animation" is a light-weight performant library to animate any element ("action") onto any other element ("effect") on the page.

It is written with an aim to promote visual continuity in web apps. To see what you can do with this, checkout the demo:

DEMO

Installation

cta.js is just 1.2KB minified & gzipped.

Note: cta.js supports AMD and commonJS module pattern out of the box.

Usage

In very basic form, you can animate an element with selector X onto an element with selector Y:

var e1 = document.querySelector(X),
	e2 = document.querySelector(Y);
cta(e1, e2);

Triggering a reverse animation;

var e1 = document.querySelector('#js-source-element'),
	e2 = document.querySelector('#js-target-element');
var reverseAnimate = cta(e1, e2);

// Reverse previous animation. `options` and `callback` can be passed to this function too.
reverseAnimate();

Specify animation duration:

var e1 = document.querySelector('#js-source-element'),
	e2 = document.querySelector('#js-target-element');
cta(e1, e2, {
	duration: 0.3 // seconds
});

Specify a callback to execute after animation:

var button = document.querySelector('#js-button'),
	hiddenModal = document.querySelector('#js-modal');
cta(button, hiddenModal, function () {
	showModal();
});

More documentation coming up.

Public API

cta(sourceElement, targetElement [, options] [, callback] )

Animate an element sourceElement onto targetElement.

Browser Support

cta.js works best on latest versions of Google Chrome, Firefox and Safari.

For all non-supported browsers, the library does nothing and fallbacks to normal behavior without any explicit handling in your code.

Contributing

Interested in contributing features and fixes?

Read more on contributing.

Changelog

See the Changelog

License

Copyright (c) 2015-2016 Kushagra Gour, http://kushagragour.in Licensed under the MIT license.

Credits

Paul Lewis - for his awesome performance tip on scaling elements.