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:

Option Description
x Animate translateX in pixels.
xp Animate translateX in percent.
y Animate translateY in pixels.
yp Animate translateY in percent.
bg Animate a background image.
bgp Animate a background image in percent.
rotate Animate rotation clockwise in degree.
scale Animate scaling.
color Animate color (needs start and stop value).
background-color Animate background-color (needs start and stop value).
border-color Animate border color (needs start and stop value).
opacity Animate 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

Option Possible value Default Description
velocity float 0.5 Animation velocity during scrolling
target mixed false Element dimension reference for animation duration.
viewport float (0 to 1) false Animation range depending on the viewport.
media integer / string false Condition 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 */ });

Slideset

Create sets and groups of items, allowing to loop through the sets.

Usage

To apply this component, add the data-uk-slideset attribute to a container element. Add the default option to the data-uk-slideset attribute, to adjust the number of items within a set.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]

Markup

<div data-uk-slideset="{default: 4}">
    <ul class="uk-grid uk-slideset">
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        ...
    </ul>
</div>

To navigate through your slides, just use the uk-slideset-nav class. This will dynamically create a navigation depending on the number of existing slides.

Markup

<div data-uk-slideset="{default: 4}">
    <ul class="uk-grid uk-slideset">
        <li>...</li>
        <li>...</li>
    </ul>
    <ul class="uk-slideset-nav">...</ul>
</div>

To switch to the adjacent slides, use the data-uk-slideset-item attribute and set the attribute to next and previous. The elements with the data-uk-slideset-item attribute need to be inside the data-uk-slideset container.

Markup

<div data-uk-slideset="{default: 4}">
    <ul class="uk-grid uk-slideset">
        <li>...</li>
        <li>...</li>
    </ul>
    <a href=""data-uk-slideset-item="previous"></a>
    <a href=""data-uk-slideset-item="next"></a>
</div>

Slidenav and Dotnav

You can use any of the other UIkit components to navigate through a Slideset. For example the Slidenav and Dotnav can be used to style the slideset navigations as you can see below.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]

Markup

<div data-uk-slideset="{default: 4}">
    <div class="uk-slidenav-position">
        <ul class="uk-grid uk-slideset">
            <li>...</li>
            <li>...</li>
        </ul>
        <a href="" class="uk-slidenav uk-slidenav-previous" data-uk-slideset-item="previous"></a>
        <a href="" class="uk-slidenav uk-slidenav-next" data-uk-slideset-item="next"></a>
    </div>
    <ul class="uk-slideset-nav uk-dotnav uk-flex-center">...</ul>
</div>

Responsive items

The slideset supports media query based items visibility. Just add a breakpoint option, like small, medium, large to the data-uk-slideset attribute. Add the number of items you want to display from the breakpoint upwards.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]

Markup

<div data-uk-slideset="{small: 2, medium: 4, large: 6}">...</div>

Animations

There is a batch of animations which can be used to display the next set of items. Just add the animation option to the data-uk-slideset and set it to the desired animation. The animation duration can also be adjusted by using the duration option.

Animation Description
fade The items fade in and out.
scale The items scale up and down.
slide-horizontal The items slide to the side.
slide-vertical The items slide vertically.
slide-top The items slide to and from the top.
slide-bottom The items slide to and from the bottom.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]

Markup

<div data-uk-slideset="{animation: 'scale', duration: 200}">...</div>

Filter

You can also filter your slideset so that only particular items will be displayed. To do so, add the data-uk-filter attribute to each control to define the category you want to filter. Then you also need to add the data-uk-filter attribute to each slideset item to define what category the item belongs to.

NOTE The controls can be included in the slideset or referenced by adding the controls option to the data-uk-slideset attribute and passing the id to the option.

Example

Markup

<!-- The controls are included in the Slideset -->
<div data-uk-slideset>
    <ul>
        <li data-uk-filter=""><a></a></li>
        <li data-uk-filter="filter-a"><a></a></li>
        <li data-uk-filter="filter-b"><a></a></li>
    </ul>

    <ul class="uk-grid uk-slideset">
        <li data-uk-filter="filter-a"><img src=""></li>
        <li data-uk-filter="filter-b"><img src=""></li>
    </ul>
</div>

<!-- The controls are outside the Slideset -->
<ul id="my-id">
    <li data-uk-filter=""><a></a></li>
    <li data-uk-filter="filter-a"><a></a></li>
    <li data-uk-filter="filter-b"><a></a></li>
</ul>

<div data-uk-slideset"{controls: '#my-id'}">
    <ul class="uk-slideset">
        <li data-uk-filter="filter-a"><img src=""></li>
        <li data-uk-filter="filter-b"><img src=""></li>
    </ul>
</div>

JavaScript options

Option Possible value Default Description
default integer 1 Default visible items in a set
small integer null Visible items in a set at small breakpoint
medium integer null Visible items in a set at medium breakpoint
large integer null Visible items in a set at large breakpoint
xlarge integer null Visible items in a set at xlarge breakpoint
animation string 'fade' Animation name
duration integer 200 Animation duration in ms
delay integer 100 Animation delay between items in a set
filter string '' Items filter
autoplay false Defines whether or not the slideset items should switch automatically.
pauseOnHover true Pause autoplay when hovering a slideset.
autoplayInterval 7000 Defines the timespan between switching slideset items.

Init element manually

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

Events

Name Parameter Description
show.uk.slideset event, set On set show

Slider

Create a list of items to use as a responsive carousel slider

The slider is a responsive display of elements that can be scrolled through using the mouse or touch gestures.

Usage

To apply the Slider component, add the data-uk-slider attribute to a container element around a .uk-slider-container element. Add a list of items and assign the .uk-slider class to the list. Use the .uk-width-* and .uk-grid-width-* classes to determine how many elements are visible at once.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]
  • 11 [600x400]
  • 12 [600x400]

Markup

<div data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-4">
            <li>...</li>
            ...
        </ul>
    </div>

</div>

The slider itself can be scrolled with click and drag of the mouse or swiping on touch devices. It is a good idea to also add a clickable slidenav navigation. The slidenav adds arrows buttons that appear when you hover the slider.

Example

<div class="uk-slidenav-position" data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-4">
            <li>...</li>
            ...
        </ul>
    </div>

    <a href="" class="uk-slidenav uk-slidenav-contrast uk-slidenav-previous" data-uk-slider-item="previous"></a>
    <a href="" class="uk-slidenav uk-slidenav-contrast uk-slidenav-next" data-uk-slider-item="next"></a>

</div>

Center Mode

By default, elements of the slider always align to the left edge of the slider container. If you want to center the elements instead, set the center attribute to true.

Note The center list element always has the class .uk-active added. You can make use of that if you want to highlight the center element.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]
  • 11 [600x400]
  • 12 [600x400]

Markup

<div data-uk-slider="{center:true}">

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-4">
            <li>...</li>
            ...
        </ul>
    </div>


</div>

Disable Infinite Scrolling

By default, the slider loops through all items. To disable that behaviour, set the infinite parameter to false. This works both with center mode enabled and disabled.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]
  • 11 [600x400]
  • 12 [600x400]

Markup

<div data-uk-slider="{infinite: false}">

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-4">
            <li>...</li>
            ...
        </ul>
    </div>

</div>

Item gutter

If you want some spacing between your elements, add the .uk-grid class to the slider container. The elements will then be spaced according to the grid gutter.

Note You can use the modifiers uk-grid-medium and uk-grid-small to change the gutter.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]

Item width

To set the widths of your elements, use the width classes from the UIkit grid. Either use the uk-grid-width-* classes on the slider container or use individual widths per list item using the uk-width-* classes.

Example: Individual widths

  • 1 [400x200]
  • 2 [240x200]
  • 3 [480x200]
  • 4 [300x200]
  • 5 [400x200]
  • 6 [240x200]
  • 1 [400x200]
  • 2 [240x200]
  • 3 [480x200]
  • 4 [300x200]
  • 5 [400x200]
  • 6 [240x200]
  • 1 [400x200]
  • 2 [240x200]
  • 3 [480x200]
  • 4 [300x200]
  • 5 [400x200]
  • 6 [240x200]

Markup

<div data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider">
            <li class="uk-width-1-3">...</li>
            <li class="uk-width-1-5">...</li>
            <li class="uk-width-2-5">...</li>
            ...
        </ul>
    </div>

</div>

Responsive behaviour

To adapt to different viewports, you can use the responsive grid classes. In the following example, the slider displays four items on large viewports, three on medium and just one item on small ones.

Example: Responsive widths

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]

Markup

<div data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-3 uk-grid-width-large-1-4">
            <li>...</li>
            ...
        </ul>
    </div>

</div>

Fullscreen mode

The slider includes a fullscreen mode where each slide stretches to 100% the height of the viewport.

Markup

<div data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider uk-slider-fullscreen">
            <li>...</li>
            ...
        </ul>
    </div>

</div>

JavaScript options

Option Possible value Default Description
center boolean false Center items mode
threshold integer 10 Mouse movement threshold in pixel until trigger element dragging
infinite boolean true Infinite scrolling
activecls string uk-active Class added on active item in center mode
autoplay boolean false Defines whether or not the slider items should switch automatically
pauseOnHover boolean true Pause autoplay when hovering a slider
autoplayInterval integer 7000 Defines the timespan between switching slider items

Init element manually

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

Events

Name Parameter Description
focusitem.uk.slider event, index, item On item focus

Dynamic Grid

Create a multi-column, dynamic grid layout whose items can be sorted and filtered.

The Dynamic Grid component allows you to create a dynamic and responsive grid layout utilizing the Grid component. Grid items will arrange themselves fluently and seamlessly for a gap-free multi-column layout on all device sizes.


Usage

To apply this component, add the data-uk-grid attribute to the container element. Set the width of the grid items by using the uk-width-* or .uk-grid-width-* classes from the Grid component.

Example

1
2
3
4
5
6
7
8

Markup

<!-- This is a grid using uk-width-* on each item -->
<div data-uk-grid>
    <div class="uk-width-small-1-2 uk-width-medium-1-4">...</div>
    <div class="uk-width-small-1-2 uk-width-medium-1-4">...</div>
</div>

<!-- This is a grid using uk-grid-width-* on the grid itself -->
<div class="uk-grid-width-small-1-2 uk-grid-width-medium-1-4" data-uk-grid>
    <div>...</div>
    <div>...</div>
</div>

Grid Gutter

Divide grid items with a gutter by adding the {gutter: 20} option to the data attribute. In this case the gutter will be 20px wide.

Example

1
2
3
4
5
6
7
8

Markup

<div data-uk-grid="{gutter: 20}">...</div>

Filtering

You can also filter your grid so that only particular items will be displayed. To do so, add the {controls: '#my-id'} option to the data-attribute to target the id for the filter controls. Each control needs to have the data-uk-filter attribute to define the category you want to filter. Then you also need to add the data-uk-filter attribute to each grid item to define what category the item belongs to. Separate multiple categories by comma.

Example

A 1
B 2
A 3
B 4
B 5
A 6
B 7
A+B 8

Markup

This example is using a Subnav to filter the items.

<!-- Filter Controls -->
<ul id="my-id" class="uk-subnav">
    <li data-uk-filter=""><a href=""></a></li>
    <li data-uk-filter="filter-a"><a href=""></a></li>
    <li data-uk-filter="filter-b"><a href=""></a></li>
</ul>

<!-- Dynamic Grid -->
<div data-uk-grid="{controls: '#my-id'}">
    <div data-uk-filter="filter-a">...</div>
    <div data-uk-filter="filter-b">...</div>
    <div data-uk-filter="filter-a,filter-b">...</div>
</div>

Sorting

To sort grid items ascendingly, add the {controls: '#my-id'} option to the data-attribute to target the id for the sorting controls.

Each control needs to have the data-uk-sort attribute with a custom value that targets the category you want to be sorted, for example data-uk-sort="my-category". You also need to add a data attribute to each grid item, using your target category's name. The value contains the data which should be sorted, for example data-my-category="my-data".

Items are sorted ascendingly by default. To sort the items descendingly just add :desc to the value of the controls' data attribute, for example data-uk-sort="my-category:desc".

Example

A
B
C
D
E
F
G
H

Markup

<ul id="my-id" class="uk-subnav">
    <li data-uk-sort="my-category"><a href=""></a></li>
    <li data-uk-sort="my-category:desc"><a href=""></a></li>
</ul>

<div data-uk-grid="{controls: '#my-id'}">
    <div data-my-category="a">...</div>
    <div data-my-category="b">...</div>
</div>

Multiple categories

To use more than one category to sort grid items, use a different name for each category.

A 8
B 7
C 6
D 1
E 5
F 3
G 2
H 4

Markup

<ul id="my-id" class="uk-subnav">
    <li data-uk-sort="my-category"><a href=""></a></li>
    <li data-uk-sort="my-category:desc"><a href=""></a></li>
    <li data-uk-sort="my-category2"><a href=""></a></li>
    <li data-uk-sort="my-category2:desc"><a href=""></a></li>
</ul>

<div data-uk-grid="{controls: '#my-id'}">
    <div data-my-category="a" data-my-category2="8">...</div>
    <div data-my-category="b" data-my-category2="7">...</div>
</div>

JavaScript options

Option Possible value Default Description
colwidth integer auto Columns width
animation boolean true Animate columns on update
duration integer 200 Animation duration
gutter integer 0 Gutter between columns
controls string false Css selector to connect filter / order controls.
filter string '' Items filter

Init element manually

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

Events

Name Parameter Description
beforeupdate.uk.grid event, children On before update grid
afterupdate.uk.grid event, children On after update grid

Example

Listening for beforeupdate events with jQuery:

$(function() {
    $('[data-uk-grid]').on('beforeupdate.uk.grid', function(e, children) {
        // your event-handling goes here
    });
});

Parallax Grid

Create an effect which scrolls the single columns of a grid with different speeds.

This component allows you to add a scrolling parallax effect to columns within a Grid from the Grid component.


Usage

To apply this component, add the data-uk-grid-parallax attribute to the container element. Set the width of the grid items by using the uk-width-* or .uk-grid-width-* classes from the Grid component.

Example

1
2
3
4
5
6
7
8
9

Javascript Arguments

To adjust the scroll speed, just change the arguments of the data-uk-grid-parallax attribute, for example like this: data-uk-grid-parallax="{translate:200}"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

JavaScript options

This is an example of how to set options via attribute:

data-uk-grid-parallax="{translate:200}"
Option Possible value Default Description
translate integer 150 Translate value

Init element manually

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

More Articles ...

Chameleon I.T are a client focused consultancy seeking to deliver IT efficiency gains through software and consulting solutions.

These solutions seek to take existing systems and optimise them in conjunction with adding cutting edge technologies to complement.

 

Map

Contact us

Phone:
01727 831 383
Email:
info@chameleonit.co.uk
Mon-Fri:
9am to 5pm

Search