new UWA.Controls.Scroller(element, options)
UWA.Controls.Scroller constructor.
Available Events
| Event | Description |
|---|---|
onScrollStart |
Invoked when user starting to scroll content. |
onScrollMove |
Invoked when user mouse or touch move on the scrollable area. |
onScrollStop |
Invoked when user mouse or touch up/end/cancel on the scrollable area. |
onScrollEnd |
Invoked when user stop to scroll content (after momentum or bounce ended). |
onScrollPull |
Invoked when user start to scroll content out of boundaries. |
onKeyDown |
Invoked when user use keyboard key. |
onMouseWheel |
Invoked when user use mouse wheel. |
onRefresh |
Invoked when the content or the scroller container change or resize. |
Example
// Inject your long content that need scroller
var myContent = UWA.createElement('div', {
html: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
+ 'Fusce eu urna massa. Nullam mi odio, elementum ut viverra'
+ 'vitae, adipiscing eget est. Mauris massa neque, faucibus'
+ 'sed consequat non, congue ac diam. Donec in arcu nisi,'
+ 'sit amet scelerisque mauris. Quisque facilisis urna in'
+ 'ligula sodales ut adipiscing velit tempor. Vivamus ac felis'
+ 'mi. Sed hendrerit velit vel lacus aliquet ac gravida urna'
+ 'rhoncus. Ut semper, ligula et ultrices fermentum, magna'
+ 'augue vulputate odio, in pharetra arcu enim vel nisl.'
+ 'Etiam vulputate viverra ante sit amet congue. Mauris'
+ 'rutrum, lacus a luctus ullamcorper, magna lorem aliquam'
+ 'eros, ac iaculis orci neque in urna.'
}).inject(widget.body);
// Init Scroller with content as first argument and needed options
var myScroller = new UWA.Controls.Scroller(myContent, {
height: 50,
bounce: true,
events: {
onScrollStart: function () {
myContent.setStyle('background-color', 'blue');
},
onScrollPull: function () {
myContent.setStyle('background-color', 'red');
},
onScrollEnd: function () {
myContent.setStyle('background-color', 'green');
}
}
});
Parameters
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
element |
Object | Element arround the scroller wil be injected |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options |
Object | Options hash or a option/value pair. Properties
|
Extends
- UWA.Controls.Abstract
Mixes In
- UWA.Controls.Abstract
Index
Members
- name
- position
- direction
- scroll
- maxScroll
- scroller
- maxPage
- scrollBars
- isScrolling
- isTracking
- isDragging
- isPulling
- enabled
- defaultOptions
Methods
- destroy
- setOptions
- buildNative
- buildSkeleton
- initEvents
- handleEvent
- scrollTo
- scrollToPage
- scrollToElement
- setPosition
- stopScroll
- scrollToPosition
- triggerOnScrollStart
- triggerOnScroll
- triggerOnScrollEnd
- getPosition
- getResetPosition
- isInViewport
- isMaxPosition
- hasOverflow
- setSize
- setCursor
- focus
- updateGhostPosition
- createDebugPixel
- getPage
- getSnapSize
- getScrollSize
- bounce
- momentum
- snap
- onScrollInit
- onScrollMove
- onScrollStop
- onScrollStart
- onScroll
- onScrollEnd
- onScrollPull
- onKeyDown
- onMouseWheel
- onRefresh
Members
-
<protected> name
-
Properties:
Name Type Description nameObject Controls identifier
-
<protected> position
-
Properties:
Name Type Description positionObject Last scheduled scroller position.
-
<protected> direction
-
Properties:
Name Type Description directionObject Last scroller direction.
-
<protected> scroll
-
Properties:
Name Type Description scrollObject hash or a key/value pair with scroller width/height and x/y axis state.
-
<protected> maxScroll
-
Properties:
Name Type Description maxScrollObject axis/value pair with max scroll value.
-
<protected> scroller
-
Properties:
Name Type Description scrollerObject axis/value pair with scroller offset value.
-
<protected> maxPage
-
Properties:
Name Type Description maxPageObject axis/value pair with max page value.
-
<protected> scrollBars
-
Properties:
Name Type Description scrollBarsObject axis/value pair with scrollBars instance.
-
<protected> isScrolling
-
Properties:
Name Type Description isScrollingBoolean Define if scroller currently scrolling.
-
<protected> isTracking
-
Properties:
Name Type Description isTrackingBoolean Whether a touch event sequence is in progress.
-
<protected> isDragging
-
Properties:
Name Type Description isDraggingBoolean Whether the user has moved by such a distance that we have enabled
-
<protected> isPulling
-
Properties:
Name Type Description isPullingBoolean Define if scroller has moved out of boundaries.
-
<protected> enabled
-
Properties:
Name Type Description enabledBoolean Current scroller enable state.
-
<protected> defaultOptions
-
Properties:
Name Type Description defaultOptionsObject The default controls options.
Methods
-
destroy()
-
Destroy scroller instance and remove wrapper arround element.
-
setOptions(options) → {this}
-
Set options, automatically adds events when passed in options.
Parameters
Name Type Description optionsObject options hash or a option/value pair.
Returns
- this instance
- Type
- this
-
buildNative(element)
-
Build main dom elements using native scroller.
Parameters
Name Type Description elementDOMElement element to wrap with the scroller.
-
buildSkeleton(element)
-
Build main dom elements used by scroller.
Parameters
Name Type Description elementDOMElement element to wrap with the scroller.
-
initEvents()
-
Init scroller events.
-
handleEvent() → {Boolean}
-
Handle scroller events.
Returns
- false if event should not propagate.
- Type
- Boolean
-
scrollTo(x, y, runtime)
-
Scroll to coordinate.
Parameters
Name Type Description xNumber Target on X axis
yNumber Target on Y axis
runtimeNumber Scroll duration (default is options.scrollTime)
-
scrollToPage(pageX, pageY, runtime)
-
Scroll to page coordonate.
Parameters
Name Type Description pageXNumber Page target on X axis
pageYNumber Page target on Y axis
runtimeNumber Scroll duration (default is options.scrollTime)
-
scrollToElement(el, where)
-
Scroll until the element is shown.
Parameters
Name Type Argument Description elHTMLElement the element to show
whereString <optional>
'start', 'center', 'end', or an object with properties 'x' and 'y' with one of those value: try to put the element in the beginning, the center or the end of the scrollable zone. Default to 'center'.
-
setPosition(x, y, runtime, hideScrollBars)
-
Scroll to position and handle scrollbar position/display.
Parameters
Name Type Description xNumber New x position axis position
yNumber New y position axis position
runtimeNumber Position translation duration
hideScrollBarsBoolean Hide scrollbar during scroll
-
stopScroll()
-
Stop current scroll animation.
-
scrollToPosition(newPosition, runtime)
-
Scroll to position.
Parameters
Name Type Description newPositionObject Position axis/value pair
runtimeNumber Scroll duration
-
triggerOnScrollStart()
-
TODO.
-
triggerOnScroll()
-
TODO.
-
triggerOnScrollEnd()
-
TODO.
-
getPosition(round) → {Object}
-
Get current scroller position.
Note: Using WebKitCSSMatrix feature detectiom when using CSS transform.
Parameters
Name Type Description roundBoolean Round position to integer instead of float
Returns
Position axis/value pair.
- Type
- Object
-
getResetPosition() → {Object}
-
Get postion inside boundaries.
Returns
- position axis/value pair.
Note: * Used after scrollEnd when bounce options is enable to restore position to the edges.
- Type
- Object
-
isInViewport(element, partially, axis) → {Boolean}
-
Check if the element is visible in the scroller viewport.
Parameters
Name Type Argument Description elementElement The element to check visibility
partiallyBoolean If any part of the element is visible in the viewport or only entirely visible
axisString <optional>
Optionnal specific axis to check ('x' or 'y') (default: both)
Returns
trueif the element is in the scroller viewport elsefalse.- Type
- Boolean
-
isMaxPosition(axis, position, direction) → {Boolean}
-
Whether or not the position reach the edge of scroller on the given axis.
Parameters
Name Type Description axisString 'x' or 'y'
positionObject directionObject Returns
trueif scroller reach the edge of scroller on the given axis elsefalse.- Type
- Boolean
-
hasOverflow(axis) → {Boolean}
-
Whether or not the scroller needs a scrollbar on the given axis.
Parameters
Name Type Description axisString 'x' or 'y'
Returns
trueif scroller has overflow on the given axis elsefalse.- Type
- Boolean
-
setSize(size)
-
Change scroller dimensions.
Example
scroller.setSize({height: '800px'});Parameters
Name Type Description sizeObject The width and/or the height to setup
-
setCursor(cursor)
-
Change scroller cursor.
Example
scroller.setCursor('grabbing');Parameters
Name Type Description cursorString New scroller cursor (e.g: grab, grabbing, col-resize, row-resize)
-
focus() → {Scroller}
-
Set the focus to the scroller. When the scroller has the focus, it can be scrolled with the keyboard arrows.
Returns
this instance
- Type
- Scroller
-
updateGhostPosition(position)
-
Update Ghost pixel position that is used to avoid bad click events.
Parameters
Name Type Description positionObject position axis/value pair.
-
createDebugPixel(position, color, msg, clear)
-
Create Ghost pixel position that is used to avoid bad click events.
Parameters
Name Type Description positionObject position axis/value pair.
colorString pixel color.
msgString debug color.
clearBool if true will remove previous pixel.
-
getPage() → {Object}
-
Get current axis pages offset.
Returns
Pages axis/value pair.
- Type
- Object
-
getSnapSize() → {Object}
-
Get current axis snap size.
Returns
Snap size axis/value pair.
- Type
- Object
-
getScrollSize() → {Object}
-
Get current axis scroll size.
Returns
Scroll size axis/value pair.
- Type
- Object
-
bounce(newPosition) → {Object}
-
Calculate new position and transition duration for bounce options.
Parameters
Name Type Description newPositionNumber next position.
Returns
- position axis/value pair.
- Type
- Object
-
momentum(x, y, startPosition, endPosition, duration) → {Object}
-
Calculate new position and transition duration for momentum options.
Parameters
Name Type Description xNumber new x position axis position.
yNumber new y position axis position.
startPositionObject start position axis/value pair.
endPositionObject end position axis/value pair.
durationNumber duration of transition from startPosition to endPosition.
Returns
- position axis/value pair.
Note: - http://code.google.com/mobile/articles/webapp_fixed_ui.html#momentum - http://physics.stackexchange.com/questions/33323/end-position-of-movement-factoring-in-deceleration
- Type
- Object
-
snap(x, y, position) → {Object}
-
Calculate new position and transition duration for snap options.
Parameters
Name Type Description xNumber new x position axis position.
yNumber new y position axis position.
positionObject last position axis/value pair (default is <position> property value).
Returns
- position axis/value pair.
- Type
- Object
-
onScrollInit(event)
-
Invoked when user click on left button or touch the scrollable area.
Parameters
Name Type Description eventEvent a standart DOM event.
-
onScrollMove(event)
-
Invoked when user mouse or touch move on the scrollable area.
Parameters
Name Type Description eventEvent a standart DOM event.
-
onScrollStop(event)
-
Invoked when user mouse or touch up/end/cancel on the scrollable area.
Parameters
Name Type Description eventEvent a standart DOM event.
-
onScrollStart()
-
Invoked when scroller starting to scroll content.
-
onScroll()
-
Invoked when scroller scroll content.
-
onScrollEnd()
-
Invoked when scroller stop to scroll content.
-
onScrollPull()
-
Invoked when user start to scroll content out of boundaries.
-
onKeyDown(event)
-
Invoked when user use keyboard key.
Parameters
Name Type Description eventEvent a standart DOM event.
Notes: * http://unixpapa.com/js/key.html
-
onMouseWheel(event)
-
Invoked when user use mouse wheel.
Parameters
Name Type Description eventEvent a standart DOM event.
-
onRefresh()
-
Invoked when the content or the scroller container change or resize.