Parallax

Animate CSS properties depending on the scroll position of the document.

Usage

To apply this component, add the data-uk-parallax attribute to a container element. Add an option with the desired animation target value for each CSS property you want to animate.

Heading

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Markup

<div data-uk-parallax="{bg: '-200'}">...</div>

Options

UIkit provides a number of options that you can add to the data-uk-parallax attribute:

OptionDescription
xAnimate translateX in pixels.
xpAnimate translateX in percent.
yAnimate translateY in pixels.
ypAnimate translateY in percent.
bgAnimate a background image.
bgpAnimate a background image in percent.
rotateAnimate rotation clockwise in degree.
scaleAnimate scaling.
colorAnimate color (needs start and stop value).
background-colorAnimate background-color (needs start and stop value).
border-colorAnimate border color (needs start and stop value).
opacityAnimate the opacity.

NOTE You can basically animate any CSS property that has a single value, like width and height, by adding it to the attribute.

Markup

<div data-uk-parallax="{y: '-200', opacity: '0'}">...</div>

Start and stop values

Properties are always animated from the current value to the target value which you set in the option. However, you can also define a start value yourself. This is done by passing a string to the option which contains two values separated by comma.

NOTE Some properties, like colors, require a start and a stop value!

Markup

<div data-uk-parallax="{x: '-100,100', 'background-color': '#EBF7FD,#FFF1F0'}">...</div>

Nested animation

Using different animations for nested elements is a simple task. Just create another container within the first parallax container and add your options to a new data-uk-parallax attribute.

Example

Heading

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Markup

<div data-uk-parallax="{bg: -200}">
    <div data-uk-parallax="{opacity: '0,1', scale: '0,1'}">...</div>
</div>

Target Option

Usually, the animation lasts as long as the element itself is in the viewport. To start and stop the animation based on the viewport visibility of another element, use the target option. This can be helpful when using nested animations.

Example

Heading

This text is animated as long as the headline “Target Option” is in the viewport.

Markup

<div id="target-id">...</div>
<div data-uk-parallax="{target: '#target-id'}">...</div>

Velocity

To adjust the easing of the animation, add the velocity option.

Example

0.04
0.2
0.6
1
2
3
4

Markup

<div data-uk-parallax="{velocity: '0.5'}">
    ...
</div>

Viewport

Using the viewport option, the animation duration can be adjusted. With the value 1 or false the animation lasts as long as the element is in the viewport. Setting it to 0.5, for example, animates the property only in the first half of the viewport.

Example

Heading

This text is animated until it reaches the middle of the viewport.

Markup

<div data-uk-parallax="{viewport: '0.5'}">...</div>

JavaScript options

OptionPossible valueDefaultDescription
velocityfloat0.5Animation velocity during scrolling
targetmixedfalseElement dimension reference for animation duration.
viewportfloat (0 to 1)falseAnimation range depending on the viewport.
mediainteger / stringfalseCondition for the active status with a width as integer (e.g. 640) or a css media query

Init element manually

var parallax = UIkit.parallax(element, { /* options */ });

DISCLAIMER: MID CITY GYM DOES NOT GUARANTEE RESULTS, WHICH CAN VARY FROM INDIVIDUAL TO INDIVIDUAL.