Scrollmagic CSS Transitions
A small library to help simplify fade and transform (css) transitions based on the scroll position.
Uses scrollmagic under the hood.
Install
yarn add scrollmagic-css-transitions scrollmagic
Example
Define your markup and animation
Create a new listener
const scrollAnimations = triggerSelector: '.anim' triggerActiveClass: 'anim--active' triggerHook: 065;
Usage
; const scrollAnimations = options: Object;
Add the following css to enable the transitions:
Options
Use options to define selectors and transition defaults. Transition options can be applied using data attributes on the scroll child.
defaultDirection string: [top | right | bottom | left]
Default transition direction
defaultDistance string
default: 25px
Default transition distance
defaultDuration string
default: 800ms
Default transition duration
defaultDelay string
default: 0ms
Default transition delay
finishTriggerSelector string
Mark all animations as complete and remove all listeners when reaching this element
triggerActiveClass string
default: anim--active
Class name to apply to the triggerSelector
once activated
triggerHook string
default: 0.85
Percentage of the viewport to apply the triggerActiveClass
triggerSelector string
default: .anim
Mark as active when this element reaches the given triggerHook
Data Attributes
Data attributes can be placed on the trigger or child element to override transition default options.
Triggers
data-anim-offset distance
Offset the active trigger (triggerHook
) position.
Example:
Children
data-anim [time direction distance time]
Shorthand for all transition properties:
- duration
- direction
- distance
- delay
Note: Property order is only important for distinguishing between delay
and duration
. The first time unit will be considered duration
.
Examples:
// 100px from the left, transition for .3s with a 200ms delay // Properties can be omitted// 50px from the top // Duration is always the first time value parsed// Transition for .3s with a 1s delay // Transition for 1s with a default delay
data-anim-delay [time]
Transition delay
Example:
data-anim-delay [top | right | bottom | left]
Transition direction
Example:
data-anim-direction [distance]
Transition distance
Example:
data-anim-duration [time]
Transition duration
Example: