• Stars
    star
    1,652
  • Rank 27,232 (Top 0.6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Animate your 'action-to-effect' paths

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.

  • 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.
    • extraTransitionDuration - Extra duration (in seconds) of targetElement to provide visual continuity between the animation and the rendering of the targetElement. Default is 1 second.
    • 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-2016 Kushagra Gour, http://kushagragour.in Licensed under the MIT license.

Credits

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

More Repositories

1

hint.css

A CSS only tooltip library for your lovely websites.
CSS
8,366
star
2

web-maker

A blazing fast & offline frontend playground
JavaScript
2,469
star
3

superplaceholder.js

⚑Super charge your input placeholders
JavaScript
988
star
4

screenlog.js

Bring console.log on the screen
JavaScript
845
star
5

code-blast-codemirror

✨Particles blasts while typing in Codemirror
JavaScript
341
star
6

picssel-art

An app to create pixel art using only CSS
JavaScript
137
star
7

build-git-learn-git

What better way to learn Git than to implement one of your own!
136
star
8

simplezoom.js

A tiny JavaScript library to preview images, better way!
JavaScript
82
star
9

super-search

Easy to add search for your blog
JavaScript
77
star
10

vuejsfire-hackathon-starter

Hackathon starter kit based on vue.js and Firebase
Vue
71
star
11

IsoBlocks

A library to create eye-candy isometric texts.
JavaScript
54
star
12

you-dont-need-to-know-web-development

πŸ˜“ You don't need to know Web Development!
29
star
13

lollipop.css

Android Lollipop animations in CSS
HTML
20
star
14

where-to-report

CSS
19
star
15

kalu

Calculation at speed
HTML
18
star
16

kushagra.dev

My personal site and blog
JavaScript
16
star
17

AS3-Motion-Tracker

A simple webcam based motion tracker written in Actionscript 3.0
ActionScript
14
star
18

konsole.table

console.table polyfill for Node.js
JavaScript
13
star
19

Bouncy_HTML5

HTML5 version of my game Bouncy.
JavaScript
12
star
20

web-vim

Vim like text based editor for prototyping web pages with speed!
HTML
11
star
21

awesome-google-sheet

Super useful google sheets for just about anything! ⭐️
9
star
22

introduction-to-accessibility

Interactive and practical introduction to Web Accessibility for everyone
JavaScript
8
star
23

loremizer

lorem ipsum-izes any web page
JavaScript
8
star
24

a11y-for-managers

Translate Accessibility issues on a website into actual understandable feedback from dummy users.
JavaScript
8
star
25

ask-me-anything

Ask me anything
7
star
26

ggj13

HTML5 game where you see only when your heart beats!
JavaScript
6
star
27

LD23

My Ludum Dare 23 entry.
ActionScript
5
star
28

Copter

A simple copter game clone
4
star
29

Defenders-From-Past

An HTML5 game made for BYOG, April 2012
JavaScript
4
star
30

vuejs-html5mode

POC for HTML5 mode work without server-side code
JavaScript
4
star
31

js13k-2018-key-battle

My game entry for js13kgames compo 2018
CSS
3
star
32

editur

My own sweet live web editor
JavaScript
3
star
33

cssconf-asia

My slides and game source for CSSConf.Asia '14
JavaScript
2
star
34

dotfiles

My super-duper dotfiles
Shell
2
star
35

let-me-read

A chrome extension for distraction free reading.
JavaScript
2
star
36

JIDE

JIDE is an IDE for Java language written in C++ and wxWidgets.
C++
2
star
37

MMORPC-Framework

This is basically a WIP of a MMORPC ('C' stands for 'chat' here) application I am developing. It uses Node.js for the server end and Actionscript 3.0 (flash) for the client side.
2
star
38

js13k-2017-the-lost-pixel

My game entry for js13kgames compo 2017
HTML
1
star
39

js13k-2013-world-is-falling

Multiplayer game entry for jsk13 compo
JavaScript
1
star
40

pacman-html5

JavaScript
1
star
41

webdev-samachar

HTML
1
star
42

js13k-2016-remember

My entry for JS13kGames compo. Made using CSS 3D!
CSS
1
star