A tiny modern library for fast, smooth, and controllable CSS transitions.
npm install css-transit
Libraries like GSAP
or Popmotion
are not needed when dealing with basic CSS transitions, and can significantly reduce performance.
css-transit
uses a common method of triggering layout to allow inline css transitions on demand, keeping DOM changes to a minimum which allows the browser to animate smoothly.
It has been used in multiples of large client production applications over several years.
- Transition one or multiple elements between css props
gsap
-like usage withfrom
,to
,ease
,stagger
, anddelay
- Returns a
Promise
which resolves when the transition is finished (through theontransitionend
event) - Standard
easing
curves included 🎁 - Smaller than 1kb gzipped 👌
css-transit
uses a single method,cssTransition()
, which does different things based on the supplied arguments.
See below examples for more detail.
css-transit
simply sets and unsets inline styles and support any standard css props that would go into the HTMLElement.style
property. It also includes a few special props to ease development.
ease: "<value>"
can be used to provide common easing functions and self-definedcubic-bezier()
display: "<value>"
transitions will be applied at the end of transitiondelay: 500
delays the start of the transition using standardtransition-delay
clearStyles: true
clears all styles after transition finished.
css-transit
uses a single method for all transitions based on context.
// Element transition to end props
cssTransition(
element: HTMLElement,
ms: Number,
endProps: Object
)
// Element transition from starting props, to end props
cssTransition(
element: HTMLElement,
ms: Number,
fromProps: Object,
endProps: Object
)
// Multiple element transition to end props
cssTransition(
elements: Array,
ms: Number,
endProps: Object
)
// Multiple element transition from starting props, to end props
cssTransition(
elements: Array,
ms: Number,
fromProps: Object,
endProps: Object
)
// Multiple element staggered transition to end props
cssTransition(
elements: Array,
ms: Number,
endProps: Object,
staggerInterval: Number
)
// Multiple element staggered transition from starting props, to end props
cssTransition(
elements: Array,
ms: Number,
fromProps: Object,
endProps: Object,
staggerInterval: Number
)