GithubHelp home page GithubHelp logo

isabella232 / cta.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blooparksystems/cta.js

0.0 0.0 0.0 858 KB

Animate your 'action-to-effect' paths

Home Page: http://kushagragour.in/lab/ctajs/

License: MIT License

JavaScript 60.72% HTML 39.28%

cta.js's Introduction

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:

Installation

cta.js is just 1.2KB minified & gzipped.

  • Bower: bower install cta
  • NPM: npm install cta
  • Download zip.

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.

  • sourceElement - DOM Element which is the starting point of animation.
  • targetElement - DOM Element which is the end point of animation.
  • options - A map of additional options to control the animation behaviour.
    • duration - Duration (in seconds) of animation. Default is 0.3 seconds.
    • targetShowDuration - Duration (in seconds) of targetElement to become visible, if hidden initially. The library will automatically try to figure this out from the element's computed styles. Default is 0 seconds.
    • relativeToWindow - Set to true if your target element is fixed positioned in the window. Default is relative to document (works good with normal elements).
  • callback - Optional callback to execute after animation completes.

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 Kushagra Gour, http://kushagragour.in Licensed under the MIT license.

Credits

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

cta.js's People

Contributors

chinchang avatar nalinc 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.