PO Box 9406, Group 13, Sangkat 4, OU 5, Sihanoukville, Sihanouk Province, 18204 Cambodia
donboscocf.cambodia@gmail.com Mobile: +855 12 919 834 or +855 15 919 834

Scrollspy

Trigger events and animations while scrolling your page.

Usage

The scrollspy component listens to page scrolling and triggers events based on the scroll position. For example, if you scroll down a page and an element appears the first time in the viewport you can trigger a smooth animation to fade in the element.

Data attribute Description
data-uk-scrollspy="{cls:'MY-CLASS'}" Applies the class only the first time the element appears in the viewport.
data-uk-scrollspy="{cls:'MY-CLASS', repeat: true}" Applies the class everytime the element appears in the viewport.
data-uk-scrollspy="{cls:'MY-CLASS', delay:600}" Adds a delay in milliseconds to the animation.

Typically, classes from the Animation component are used together with the scrollspy.

Examples

This example uses the repeat: true option. Scroll up and down to see the triggered animations.

Fade

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Scale up

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Scale down

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Slide top

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Slide bottom

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Slide right

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Slide left

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Delay

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

Delay

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

Delay

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

Delay

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

Markup

<div data-uk-scrollspy="{cls:'uk-animation-fade'}">...</div>

<div data-uk-scrollspy="{cls:'uk-animation-fade', repeat: true}">...</div>

<div data-uk-scrollspy="{cls:'uk-animation-fade', delay:900}">...</div>

JavaScript options

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

data-uk-scrollspy="{cls:'uk-animation-fade'}"
Option Possible value Default Description
cls string ‘uk-scrollspy-inview’ Class to add when element is in view
initcls string ‘uk-scrollspy-init-inview’ Class to add when element is in view for first time
topoffset integer 0 Top offset before triggering in view
leftoffset integer 0 Left osset before triggering in view
repeat boolean false Applies the in view class everytime the element appears in the viewport.
delay integer 0 Delay time in ms

Events

You can bind callbacks to following events for custom functionality:

Name Description
uk.scrollspy.init Triggered when the element is initially in the viewport
uk.scrollspy.inview Triggered when the element is in the viewport
uk.scrollspy.outview Triggered when the element leaves the viewport

Example

$('[data-uk-scrollspy]').on('uk.scrollspy.inview', function(){
    // custom code...
});

Scrollspy Nav

To automatically update the active menu item in a menu depending on the scroll position of your site, just add the data attribute data-uk-scrollspy-nav to any navigation. Each menu item must link to the ID of its corresponding part of the site.

Data attribute Description
data-uk-scrollspy-nav Triggers the JavaScript necessary for the functionality of the scrollspy nav.
data-uk-scrollspy-nav="{closest:'MY-SELECTOR'}" Looks for the closest element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
data-uk-scrollspy-nav="{smoothscroll:true}" Applies the Smooth scroll component when skipping between different sections of the site.
data-uk-scrollspy-nav="{cls:'MY-CLASS'}" By default ScrollspyNav toggles the uk-active class. Use the cls option to use your own class name.

Markup

<ul class="uk-nav uk-nav-side" data-uk-scrollspy-nav="{closest:'li', smoothscroll:true}">
    <li><a href="#MY-ID">...</a></li>
    <li><a href="#MY-ID2">...</a></li>
</ul>

<div id="MY-ID">...</div>
<div id="MY-ID2">...</div>

JavaScript options

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

data-uk-scrollspy-nav="{smoothscroll:true}"
Option Possible value Default Description
cls string ‘uk-active’ Class to add to active element
closest CSS selector false Element selector to aply the active class to
topoffset integer 0 Sroll top-offsset
leftoffset integer 0 Sroll left-offsset
smoothscroll boolean false Scroll animation

Events

Name Parameter Description
init.uk.scrollspy event On scrollspy first init
inview.uk.scrollspy event Element entered view-port
outview.uk.scrollspy event Element left view-port

Testimonials

  • Working in Don Bosco Technical school has been an absolute pleasure so far. Being welcomed completely by the community means it only took me two months to call Sihanoukville home. Teaching English to the students here has never once been

    Elena Arellano-Templer
  • The work I have done with Don Bosco, both with teaching and helping with the Children Fund has been all too rewarding

    Maryam Mohamed
  • I am really happy to be here, because I can help poor children who want to study. Although, I cannot help them directly I feel them in my heart. Sometimes the work is hard, but I love it! 

    Pech Chanmey
  • I feel very honored to be part of Don Bosco Children Fund Cambodia. I want to help and encourage the young people of Cambodia to keep studying and to keep going for their dreams.

    Penh Sokkheng
  • Hello! I am Teacher Gary from Brisbane, Australia. I previously taught English in China and Vietnam. Now I’m pleased to be in Cambodia as a volunteer teacher at Don Bosco Sihanoukville since June 2017. It is a pleasure teaching at

    Gary Briggs

Subscribe to our newsletter

Loading
logoDon Bosco Children Fund

It is a special project of the Don Bosco Foundation of Cambodia which was opened in 1992 to outreach and care to children from disadvantage communities and orphans. It grants scholarship to poor children and is supported by international sponsors.

BRANCHES IN CAMBODIA