Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Added events : OnBounce and beforeBounce #109

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions lib/ftscroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ var FTScroller, CubicBezier;
'segmentdidchange': [],
'reachedstart': [],
'reachedend': [],
'scrollinteractionend': []
'scrollinteractionend': [],
'onBounce': [],
'beforeBounce': []
};

// MutationObserver instance, when supported and if DOM change sniffing is enabled
Expand Down Expand Up @@ -1141,6 +1143,7 @@ var FTScroller, CubicBezier;

// Amend the positions and bezier curve if necessary
if (bounceDistance) {
var bounceDistanceOrig = bounceDistance;

// If the fling moves the scroller beyond the normal scroll bounds, and
// the bounce is snapping the scroll back after the fling:
Expand Down Expand Up @@ -1235,6 +1238,7 @@ var FTScroller, CubicBezier;
bounceDistance = 0;
bounceDuration = 0;
}
_fireEvent('onBounce', { bounceDistance: bounceDistanceOrig, flingPosition: flingPosition, bounceTarget: bounceTarget, movementSpeed: movementSpeed });
}

// If no fling or bounce is required, continue
Expand Down Expand Up @@ -1790,6 +1794,7 @@ var FTScroller, CubicBezier;
_setAxisPosition = function _setAxisPosition(axis, position, animationDuration, animationBezier, boundsCrossDelay) {
var transitionCSSString, newPositionAtExtremity = null;

_fireEvent('beforeBounce', { flingDistance: position });
// Only update position if the axis node exists (DOM elements can go away if
// the scroller instance is not destroyed correctly)
if (!_scrollNodes[axis]) {
Expand Down Expand Up @@ -2179,16 +2184,18 @@ var FTScroller, CubicBezier;
_onTouchStart = function _onTouchStart(startEvent) {
var i, l, touchEvent;

// If a touch is already active, ensure that the index
// is mapped to the correct finger, and return.
if (_inputIdentifier) {
for (i = 0, l = startEvent.touches.length; i < l; i = i + 1) {
if (startEvent.touches[i].identifier === _inputIdentifier) {
_inputIndex = i;
}
}
return;
}
startEvent.stopPropagation();

// If a touch is already active, ensure that the index
// is mapped to the correct finger, and return.
if (_inputIdentifier) {
for (i = 0, l = startEvent.touches.length; i < l; i = i + 1) {
if (startEvent.touches[i].identifier === _inputIdentifier) {
_inputIndex = i;
}
}
return;
}

// Track the new touch's identifier, reset index, and pass
// the coordinates to the scroll start function.
Expand Down