Skip to content

EdamL/css-animation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSS animation plugin

Current version: 1.0

The intention of this project is to leverage the obvious benefits of CSS3 animations in a lightweight, easy to use and dependency-free Javascript plugin. The plugin contains three public methods, which mirror three common jQuery animation methods: slideToggle, fadeToggle, and animate, except with the use of CSS3 transitions rather than intervals a significant improvement in performance is achieved.

The three methods are as follows:

cssSlideToggle([duration][,easing][,complete])

CSS3 analogue for the jQuery slideToggle() method.
NOTE: padding and margin are also included in the transition so avoid !important top padding/margin styles on sliding elements.

duration

Duration of animation in milliseconds.
Default: 500

easing

A CSS3 easing value, e.g. ease-in-out, linear or cubic-bezier(0,0,1,1).
Default: 'ease'

complete

Function to call upon completion of animation.

cssFadeToggle([duration][,easing][,complete])

CSS3 analogue for the jQuery fadeToggle() method.

duration

Duration of animation in milliseconds.
Default: 500

easing

A CSS3 easing value, e.g. ease-in-out, linear or cubic-bezier(0,0,1,1).
Default: 'ease'

complete

Function to call upon completion of animation.

cssAnimate(properties, [duration][,easing][,complete])

CSS3 analogue for the jQuery animate() method.

properties

An object containing the CSS properties for the element to animate toward.
NOTE: Unlike with jQuery animate() the full CSS value should always be passed for every property, e.g. 'height' : '20px', not 'height' : 20.

duration

Duration of animation in milliseconds.
Default: 500

easing

A CSS3 easing value, e.g. ease-in-out, linear or cubic-bezier(0,0,1,1).
Default: 'ease'

complete

Function to call upon completion of animation.

Usage

jQuery

The methods can be called on a jQuery object in the usual way:

  $('#element-to-animate').cssSlideToggle();

Vanilla JS

Or, in the absence of jQuery, the methods can be called by passing a querySelector string to the CssAni namespace:

  CssAni('#element-to-animate').cssSlideToggle();

For more examples of usage, see the demos.

About

CSS animations plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published