Skip to main content

Props

All available options for scroll effect animation configurations of a parallax element are defined in the props option.

parallaxController.createElement({
el: document.querySelector('.your-element'),
props: {
// ...your props here
},
});

Configuration Props

The following properties can be provided to configure the scroll animation:

NameTypeDefaultDescription
speednumberA value representing the elements scroll speed. If less than zero scroll will appear slower. If greater than zero scroll will appear faster.
easingstring or number[]String representing an easing preset or array of params to supply to a cubic bezier easing function.
rootMarginobjectMargin to be applied as the bounds around an element. This will affect when an element is determined to be considered in the viewport. Example: { top: 100, right: 100, bottom: 100, left: 100 }
disabledbooleanfalseDisables parallax effects on individual elements when true.
shouldAlwaysCompleteAnimationbooleanfalseAlways start and end animations at the given effect values - if the element is positioned inside the view when scroll is at zero or ends in view at final scroll position, the initial and final positions are used to determine progress instead of the scroll view size.
shouldDisableScalingTranslationsbooleanfalseEnable scaling translations - translate effects that cause the element to appear in the view longer must be scaled up so that animation doesn't end early.
startScrollnumberScroll top value to begin the animation. When provided along with endScroll relative scroll values will be ignored.
endScrollnumberScroll top value to end the animation. When provided along with startScroll relative scroll values will be ignored.
targetElementHTMLElementProvides an element to track and determine the scroll progress. Use when scroll progress should be independent of parallax element's original position. See storybook for example.

CSS Effect Props

All props for creating CSS effects are defined by a start and end value represented by an array.

const translateY = [-100, 100];

parallaxController.createElement({
el: document.querySelector('.your-element'),
props: {
translateY,
},
});

How Effects Progress

The start of an effect begins when the top of the element enters the bottom of the view.

The end of an effect begins when the bottom of the element exits the top of the view.

Available CSS Effects

These are all the supported CSS effects:

NameTypeDescription
translateXstring[] or number[]Start and end translation on x-axis in %, px, vw or vh. If no unit is passed percent is assumed. Percent is based on the elements width.
translateYstring[] or number[]Start and end translation on y-axis in %, px, vw or vh. If no unit is passed percent is assumed. Percent is based on the elements height.
rotatestring[] or number[]Start and end rotation on z-axis in deg, rad, or turn. If no unit is passed deg is assumed.
rotateXstring[] or number[]Start and end rotation on x-axis in deg, rad, or turn. If no unit is passed deg is assumed.
rotateYstring[] or number[]Start and end rotation on y-axis in deg, rad, or turn. If no unit is passed deg is assumed.
rotateZstring[] or number[]Start and end rotation on z-axis in deg, rad, or turn. If no unit is passed deg is assumed.
scalenumber[]Start and end scale on x-axis and y-axis.
scaleXnumber[]Start and end scale on x-axis.
scaleYnumber[]Start and end scale on y-axis.
scaleZnumber[]Start and end scale on z-axis.
opacitynumber[]Start and end opacity value.

Callback Props

Example using onChange callback

const onChange = element => console.log(element);

parallaxController.createElement({
el: document.querySelector('.your-element'),
props: {
onChange,
},
});

All available callbacks:

NameTypeDescription
onProgressChangefunctionCallback for when the progress of an element in the viewport changes.
onChangefunctionCallback for when the progress of an element in the viewport changes and includes the Element as a parameter
onEnterfunctionCallback for when an element enters the viewport and includes the Element as a parameter.
onExitfunctionCallback for when an element exits the viewport and includes the Element as a parameter.

Easing Presets

Example of setting easing:

const easing = 'easeInCubic';

parallaxController.createElement({
el: document.querySelector('.your-element'),
props: {
easing,
},
});

The following easing values are preset and can be used as easing

ease
easeIn
easeOut
easeInOut
easeInQuad
easeInCubic
easeInQuart
easeInQuint
easeInSine
easeInExpo
easeInCirc
easeOutQuad
easeOutCubic
easeOutQuart
easeOutQuint
easeOutSine
easeOutExpo
easeOutCirc
easeInOutQuad
easeInOutCubic
easeInOutQuart
easeInOutQuint
easeInOutSine
easeInOutExpo
easeInOutCirc
easeInBack
easeOutBack
easeInOutBack

Easing Individual Effects

You can provide various easing values to each effect by defining it as the third element in the array

const translateY = [-100, 100, 'easeInOut'];
const scale = [0, 1, 'easeOutBack'];

parallaxController.createElement({
el: document.querySelector('.your-element'),
props: {
translateY,
scale,
},
});

Cubic Bezier Easing Function

Just like with CSS cubic-bezier(0.2,-0.67,1,-0.62);, you can supply the 4 params to a custom bezier function.

const easing = [0.2, -0.6, 1, -0.6];