overscroll
Version:
37 lines (29 loc) • 1.08 kB
JavaScript
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
import compose from './utils/compose';
import getScope from './scope';
import init from './init';
function OverScroll(scope) {
var mode = scope.mode,
animation = scope.animation,
initialPosition = scope.position,
onDestroy = scope.onDestroy,
onInit = scope.onInit;
var _animation$run = animation.run(),
scrollTo = _animation$run.scrollTo,
position = _animation$run.position,
scrollToSection = _animation$run.scrollToSection;
if (mode === 'scroll') {
scrollTo.apply(undefined, _toConsumableArray(initialPosition).concat([true]));
}
if (mode === 'section') {
scrollToSection(initialPosition, true);
}
// 初始化事件
onInit();
return {
position: position,
scrollTo: mode === 'scroll' ? scrollTo : scrollToSection,
destroy: onDestroy
};
}
export default compose(OverScroll, init, getScope);