# Scroll

Handles scrolling, which is implemented in JavaScript in webOS.

## Classes

### Scroll.ScrollableElement

Created with `Scroll.createScrollableElement`.

#### Scroll.ScrollableElement Methods

##### Scroll.ScrollableElement#adjustBy

>     Scroll.ScrollableElement#adjustBy(dx, dy) -> undefined

- `dx` (Number | undefined) – The amount to change x by.
- `dy` (Number | undefined) – The amount to change y by.

Scrolls the element by the amount specified by (dx, dy). Ignores a coordinate if it's undefined.

##### Scroll.ScrollableElement#getScrollPosition

>     Scroll.ScrollableElement#getScrollPosition() -> Object

Returns an object with the current scroller position:

- `top` (Number): The top coordinate.
- `left` (Number): The left coordinate.

##### Scroll.ScrollableElement#revealBottom

>     Scroll.ScrollableElement#revealBottom([animate]) -> undefined

- `animate` (boolean) – If truthy, animates the scrolling.

Scrolls to the bottom of the scrollable area.

##### Scroll.ScrollableElement#revealElement

>     Scroll.ScrollableElement#revealElement(el[,animate]) -> Number

- `el` (HTMLElement) – The element you want to show
- `animate` (boolean) – If truthy, animates the scrolling.

Takes an element and scrolls to the bottom of it if it's below, or to the top of it if it's above.

Returns the number of pixels to scroll in the Y direction. The X direction does not scroll.

##### Scroll.ScrollableElement#revealTop

>     Scroll.ScrollableElement#revealTop([animate]) -> undefined

- `animate` (boolean) – If truthy, animates the scrolling.

Scrolls to the top of the scrollable area.

##### Scroll.ScrollableElement#scrollTo

>     Scroll.ScrollableElement#scrollTo(x, y[, animate]) -> undefined

- `x` (Number | undefined) – The x coordinate to scroll to.
- `y` (Number | undefined) – The y coordinate to scroll to.
- `animate` (boolean) – If truthy, animates the scrolling.

Scroll to the coordinate specified. If either coordinate is undefined, it is ignored.

## Class Methods

### Scroll.createScrollableElement

>     Scroll.createScrollableElement(el[, direction]) -> Scroll.ScrollableElement

- `el` (DOMElement) – The element you want to be able to scroll.
- `direction` (String) – Limit the direction of the scrolling. Default is to freely scroll both vertically and horizontally. Valid values for this argument are 'vertical', 'horizontal' or 'free'

This takes an element and wraps it in the necessary logic to make it scrollable. Will handle flicks and drags, and fires the events documented in the `Scroll` namespace as appropriate.

#### Example

    // This element will only scroll up and down, like a list.
    var myElement = document.getElementById('my-content');
    Mojo.Core.Scroll.createScrollableElement(myElement, "vertical");

### Scroll.makeViewportScrollable

>     Scroll.makeViewportScrollable(document[, axes]) -> Scroll.ScrollableElement

- `document` (HTMLDocument) – The document whose body you want to make scrollable.
- `axes` (Array) – An array of dimensions indicating which directions you want the scroller to operate in. Valid values are ["x"], ["y"], and ["x", "y"]

This function makes the body of the provided document scrollable. It is a convenience function for the common case where the developer wants their entire window to scroll.

## Constants

### Scroll.scrollEnd

The event that fires when scrolling stops. Fires on the scrollable element.

### Scroll.scrolling

The event that fires while scrolling.

This event is throttled, but still should fire frequently to do content updates. Keep in mind that this event fires on the animation loop's critical path, so any work done in this event handler can potentially cause skips in the animation.

Fires on the scrollable element.

### Scroll.scrollStart

The event that fires when scrolling starts. Fires on the scrollable element.