Module: UWA/Utils/Scroll

UWA/Utils/Scroll

Index

Methods

<static> UWA.Utils.Scroll.smoothScroll(element, end, options)

Animate the scroll of an element

Example
var button = UWA.createElement('button', {
    type: 'button',
    text: 'Scroll to top',
    events: {
        click: function () {
            UWA.Utils.Scroll.smoothScroll(scrollableElement, {top: 0}, {
                onComplete: function () {
                    // Hide the button when we are at the top
                    button.hide();
                }
            });
        }
    }
});
Parameters
Name Type Description
element Element

the scrollable element

end Object

scroll destination

Properties
Name Type Description
top Number

scroll top destination

left Number

scroll left destination

options Object

option hash

Properties
Name Type Description
onComplete Function

callback called when the scroll is finished

<static> UWA.Utils.Scroll.scrollToElement(element, options)

Scroll until an element is visible

Example
UWA.Utils.Scroll.scrollToElement(element, {
    smooth: true,
    onComplete: function () {
        console.log('Scroll animation complete!');
    }
});
Parameters
Name Type Description
element Element

the element to show

options Object

option hash

Properties
Name Type Argument Default Description
top Boolean <optional>
false

if the element should be on top even if it is bellow the scrollable zone

bottom Boolean <optional>
false

if the element should be at the bottom even if it is on top of the scrollable zone

margin Number <optional>
0

add a space around the element

scrollable Element <optional>
first overflowing parent

the scrollable element to scroll

smooth Boolean <optional>
false

be smooth

onComplete Function <optional>

callback called when the scroll is finished

<static> UWA.Utils.Scroll.preventParentScroll(element, options) → {Function}

Prevent the scroll of any element containing the passed element. This is usefull when you want a small zone the user can scroll without scrolling the whole page body.

Example
var scroller = UWA.createElement('div', { styles: { overflow: 'auto' } });
UWA.Utils.Scroll.preventParentScroll(scroller);
scroller.inject(parent);
Parameters
Name Type Argument Description
element DOMElement

the element (scrollable or containing scrollable elements) that should not impact the parent scroll.

options Object <optional>

a object containing options

Properties
Name Type Argument Default Description
onlyScrollable Boolean <optional>
true

by default, the scroll will be prevented only if the scroll occurs in a scrollable element. Set this option to false to prevent scroll on non-scrollable elements.

Returns

to remove the scroll prevention

Type
Function