From 700788bde2c8c813dc2908cc39fe54d7e82024b2 Mon Sep 17 00:00:00 2001 From: ustbhuangyi <280309453@qq.com> Date: Fri, 17 Nov 2017 00:12:00 +0800 Subject: [PATCH] build --- dist/bscroll.esm.js | 1900 +++++++++++++++++++++++++++++++++++++++++++ dist/bscroll.js | 4 +- dist/bscroll.min.js | 4 +- 3 files changed, 1904 insertions(+), 4 deletions(-) create mode 100644 dist/bscroll.esm.js diff --git a/dist/bscroll.esm.js b/dist/bscroll.esm.js new file mode 100644 index 00000000..ac5e90f0 --- /dev/null +++ b/dist/bscroll.esm.js @@ -0,0 +1,1900 @@ +/*! + * better-normal-scroll v1.4.2 + * (c) 2016-2017 ustbhuangyi + * Released under the MIT License. + */ +var slicedToArray = function () { + function sliceIterator(arr, i) { + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i["return"]) _i["return"](); + } finally { + if (_d) throw _e; + } + } + + return _arr; + } + + return function (arr, i) { + if (Array.isArray(arr)) { + return arr; + } else if (Symbol.iterator in Object(arr)) { + return sliceIterator(arr, i); + } else { + throw new TypeError("Invalid attempt to destructure non-iterable instance"); + } + }; +}(); + + + + + + + + + + + + + +var toConsumableArray = function (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); + } +}; + +function eventMixin(BScroll) { + BScroll.prototype.on = function (type, fn) { + var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this; + + if (!this._events[type]) { + this._events[type] = []; + } + + this._events[type].push([fn, context]); + }; + + BScroll.prototype.once = function (type, fn) { + var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this; + + var fired = false; + + function magic() { + this.off(type, magic); + + if (!fired) { + fired = true; + fn.apply(context, arguments); + } + } + // 将参数中的回调函数挂载在magic对象的fn属性上,为了执行off方法的时候,暴露对应的函数方法 + magic.fn = fn; + + this.on(type, magic); + }; + + BScroll.prototype.off = function (type, fn) { + var _events = this._events[type]; + if (!_events) { + return; + } + + var count = _events.length; + while (count--) { + // 移除通过on或者once绑定的回调函数 + if (_events[count][0] === fn || _events[count][0] && _events[count][0].fn === fn) { + _events[count][0] = undefined; + } + } + }; + + BScroll.prototype.trigger = function (type) { + var events = this._events[type]; + if (!events) { + return; + } + + var len = events.length; + var eventsCopy = [].concat(toConsumableArray(events)); + for (var i = 0; i < len; i++) { + var event = eventsCopy[i]; + + var _event = slicedToArray(event, 2), + fn = _event[0], + context = _event[1]; + + if (fn) { + fn.apply(context, [].slice.call(arguments, 1)); + } + } + }; +} + +var elementStyle = document.createElement('div').style; + +var vendor = function () { + var transformNames = { + webkit: 'webkitTransform', + Moz: 'MozTransform', + O: 'OTransform', + ms: 'msTransform', + standard: 'transform' + }; + + for (var key in transformNames) { + if (elementStyle[transformNames[key]] !== undefined) { + return key; + } + } + + return false; +}(); + +function prefixStyle(style) { + if (vendor === false) { + return false; + } + + if (vendor === 'standard') { + return style; + } + + return vendor + style.charAt(0).toUpperCase() + style.substr(1); +} + +function addEvent(el, type, fn, capture) { + el.addEventListener(type, fn, { passive: false, capture: !!capture }); +} + +function removeEvent(el, type, fn, capture) { + el.removeEventListener(type, fn, { passive: false, capture: !!capture }); +} + +function offset(el) { + var left = 0; + var top = 0; + + while (el) { + left -= el.offsetLeft; + top -= el.offsetTop; + el = el.offsetParent; + } + + return { + left: left, + top: top + }; +} + +var transform = prefixStyle('transform'); + +var hasPerspective = prefixStyle('perspective') in elementStyle; +var hasTouch = 'ontouchstart' in window; +var hasTransform = transform !== false; +var hasTransition = prefixStyle('transition') in elementStyle; + +var style = { + transform: transform, + transitionTimingFunction: prefixStyle('transitionTimingFunction'), + transitionDuration: prefixStyle('transitionDuration'), + transitionProperty: prefixStyle('transitionProperty'), + transitionDelay: prefixStyle('transitionDelay'), + transformOrigin: prefixStyle('transformOrigin'), + transitionEnd: prefixStyle('transitionEnd') +}; + +var TOUCH_EVENT = 1; +var MOUSE_EVENT = 2; + +var eventType = { + touchstart: TOUCH_EVENT, + touchmove: TOUCH_EVENT, + touchend: TOUCH_EVENT, + + mousedown: MOUSE_EVENT, + mousemove: MOUSE_EVENT, + mouseup: MOUSE_EVENT +}; + +function getRect(el) { + if (el instanceof window.SVGElement) { + var rect = el.getBoundingClientRect(); + return { + top: rect.top, + left: rect.left, + width: rect.width, + height: rect.height + }; + } else { + return { + top: el.offsetTop, + left: el.offsetLeft, + width: el.offsetWidth, + height: el.offsetHeight + }; + } +} + +function preventDefaultException(el, exceptions) { + for (var i in exceptions) { + if (exceptions[i].test(el[i])) { + return true; + } + } + return false; +} + +function tap(e, eventName) { + var ev = document.createEvent('Event'); + ev.initEvent(eventName, true, true); + ev.pageX = e.pageX; + ev.pageY = e.pageY; + e.target.dispatchEvent(ev); +} + +function click(e) { + var target = e.target; + + if (!/(SELECT|INPUT|TEXTAREA)/i.test(target.tagName)) { + var ev = document.createEvent(window.MouseEvent ? 'MouseEvents' : 'Event'); + // cancelable 设置为 false 是为了解决和 fastclick 冲突问题 + ev.initEvent('click', true, false); + ev._constructed = true; + target.dispatchEvent(ev); + } +} + +function prepend(el, target) { + if (target.firstChild) { + before(el, target.firstChild); + } else { + target.appendChild(el); + } +} + +function before(el, target) { + target.parentNode.insertBefore(el, target); +} + +function getNow() { + return window.performance && window.performance.now ? window.performance.now() + window.performance.timing.navigationStart : +new Date(); +} + +function extend(target) { + for (var _len = arguments.length, rest = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + rest[_key - 1] = arguments[_key]; + } + + for (var i = 0; i < rest.length; i++) { + var source = rest[i]; + for (var key in source) { + target[key] = source[key]; + } + } + return target; +} + +var DEFAULT_OPTIONS = { + startX: 0, + startY: 0, + scrollX: false, + scrollY: true, + freeScroll: false, + directionLockThreshold: 5, + eventPassthrough: '', + click: false, + tap: false, + bounce: true, + bounceTime: 700, + momentum: true, + momentumLimitTime: 300, + momentumLimitDistance: 15, + swipeTime: 2500, + swipeBounceTime: 500, + deceleration: 0.001, + flickLimitTime: 200, + flickLimitDistance: 100, + resizePolling: 60, + probeType: 0, + preventDefault: true, + preventDefaultException: { + tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ + }, + HWCompositing: true, + useTransition: true, + useTransform: true, + bindToWrapper: false, + disableMouse: hasTouch, + disableTouch: !hasTouch, + /** + * for picker + * wheel: { + * selectedIndex: 0, + * rotate: 25, + * adjustTime: 400 + * wheelWrapperClass: 'wheel-scroll', + * wheelItemClass: 'wheel-item' + * } + */ + wheel: false, + /** + * for slide + * snap: { + * loop: false, + * el: domEl, + * threshold: 0.1, + * stepX: 100, + * stepY: 100, + * listenFlick: true + * } + */ + snap: false, + /** + * for scrollbar + * scrollbar: { + * fade: true + * } + */ + scrollbar: false, + /** + * for pull down and refresh + * pullDownRefresh: { + * threshold: 50, + * stop: 20 + * } + */ + pullDownRefresh: false, + /** + * for pull up and load + * pullUpLoad: { + * threshold: 50 + * } + */ + pullUpLoad: false +}; + +function initMixin(BScroll) { + BScroll.prototype._init = function (el, options) { + this._handleOptions(options); + + // init private custom events + this._events = {}; + + this.x = 0; + this.y = 0; + this.directionX = 0; + this.directionY = 0; + + this._addDOMEvents(); + + this._initExtFeatures(); + + this._watchTransition(); + + this.refresh(); + + if (!this.options.snap) { + this.scrollTo(this.options.startX, this.options.startY); + } + + this.enable(); + }; + + BScroll.prototype._handleOptions = function (options) { + this.options = extend({}, DEFAULT_OPTIONS, options); + + this.translateZ = this.options.HWCompositing && hasPerspective ? ' translateZ(0)' : ''; + + this.options.useTransition = this.options.useTransition && hasTransition; + this.options.useTransform = this.options.useTransform && hasTransform; + + this.options.preventDefault = !this.options.eventPassthrough && this.options.preventDefault; + + // If you want eventPassthrough I have to lock one of the axes + this.options.scrollX = this.options.eventPassthrough === 'horizontal' ? false : this.options.scrollX; + this.options.scrollY = this.options.eventPassthrough === 'vertical' ? false : this.options.scrollY; + + // With eventPassthrough we also need lockDirection mechanism + this.options.freeScroll = this.options.freeScroll && !this.options.eventPassthrough; + this.options.directionLockThreshold = this.options.eventPassthrough ? 0 : this.options.directionLockThreshold; + + if (this.options.tap === true) { + this.options.tap = 'tap'; + } + }; + + BScroll.prototype._addDOMEvents = function () { + var eventOperation = addEvent; + this._handleDOMEvents(eventOperation); + }; + + BScroll.prototype._removeDOMEvents = function () { + var eventOperation = removeEvent; + this._handleDOMEvents(eventOperation); + }; + + BScroll.prototype._handleDOMEvents = function (eventOperation) { + var target = this.options.bindToWrapper ? this.wrapper : window; + eventOperation(window, 'orientationchange', this); + eventOperation(window, 'resize', this); + + if (this.options.click) { + eventOperation(this.wrapper, 'click', this, true); + } + + if (!this.options.disableMouse) { + eventOperation(this.wrapper, 'mousedown', this); + eventOperation(target, 'mousemove', this); + eventOperation(target, 'mousecancel', this); + eventOperation(target, 'mouseup', this); + } + + if (hasTouch && !this.options.disableTouch) { + eventOperation(this.wrapper, 'touchstart', this); + eventOperation(target, 'touchmove', this); + eventOperation(target, 'touchcancel', this); + eventOperation(target, 'touchend', this); + } + + eventOperation(this.scroller, style.transitionEnd, this); + }; + + BScroll.prototype._initExtFeatures = function () { + if (this.options.snap) { + this._initSnap(); + } + if (this.options.scrollbar) { + this._initScrollbar(); + } + if (this.options.pullUpLoad) { + this._initPullUp(); + } + if (this.options.pullDownRefresh) { + this._initPullDown(); + } + if (this.options.wheel) { + this._initWheel(); + } + }; + + BScroll.prototype.handleEvent = function (e) { + switch (e.type) { + case 'touchstart': + case 'mousedown': + this._start(e); + break; + case 'touchmove': + case 'mousemove': + this._move(e); + break; + case 'touchend': + case 'mouseup': + case 'touchcancel': + case 'mousecancel': + this._end(e); + break; + case 'orientationchange': + case 'resize': + this._resize(); + break; + case 'transitionend': + case 'webkitTransitionEnd': + case 'oTransitionEnd': + case 'MSTransitionEnd': + this._transitionEnd(e); + break; + case 'click': + if (this.enabled && !e._constructed) { + if (!preventDefaultException(e.target, this.options.preventDefaultException)) { + e.preventDefault(); + } + e.stopPropagation(); + } + break; + } + }; + + BScroll.prototype.refresh = function () { + var wrapperRect = getRect(this.wrapper); + this.wrapperWidth = wrapperRect.width; + this.wrapperHeight = wrapperRect.height; + + var scrollerRect = getRect(this.scroller); + this.scrollerWidth = scrollerRect.width; + this.scrollerHeight = scrollerRect.height; + + var wheel = this.options.wheel; + if (wheel) { + this.items = this.scroller.children; + this.options.itemHeight = this.itemHeight = this.items.length ? this.scrollerHeight / this.items.length : 0; + if (this.selectedIndex === undefined) { + this.selectedIndex = wheel.selectedIndex || 0; + } + this.options.startY = -this.selectedIndex * this.itemHeight; + this.maxScrollX = 0; + this.maxScrollY = -this.itemHeight * (this.items.length - 1); + } else { + this.maxScrollX = this.wrapperWidth - this.scrollerWidth; + this.maxScrollY = this.wrapperHeight - this.scrollerHeight; + } + + this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0; + this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0; + + if (!this.hasHorizontalScroll) { + this.maxScrollX = 0; + this.scrollerWidth = this.wrapperWidth; + } + + if (!this.hasVerticalScroll) { + this.maxScrollY = 0; + this.scrollerHeight = this.wrapperHeight; + } + + this.endTime = 0; + this.directionX = 0; + this.directionY = 0; + this.wrapperOffset = offset(this.wrapper); + + this.trigger('refresh'); + + this.resetPosition(); + }; + + BScroll.prototype.enable = function () { + this.enabled = true; + }; + + BScroll.prototype.disable = function () { + this.enabled = false; + }; + + BScroll.prototype._watchTransition = function () { + var isInTransition = false; + var me = this; + var prePointerEvents = this.scroller.style.pointerEvents || 'auto'; + Object.defineProperty(this, 'isInTransition', { + get: function get() { + return isInTransition; + }, + set: function set(newVal) { + isInTransition = newVal; + if (isInTransition) { + me.scroller.style.pointerEvents = 'none'; + } else { + me.scroller.style.pointerEvents = prePointerEvents; + } + } + }); + }; +} + +var ease = { + // easeOutQuint + swipe: { + style: 'cubic-bezier(0.23, 1, 0.32, 1)', + fn: function fn(t) { + return 1 + --t * t * t * t * t; + } + }, + // easeOutQuard + swipeBounce: { + style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)', + fn: function fn(t) { + return t * (2 - t); + } + }, + // easeOutQuart + bounce: { + style: 'cubic-bezier(0.165, 0.84, 0.44, 1)', + fn: function fn(t) { + return 1 - --t * t * t * t; + } + } +}; + +function momentum(current, start, time, lowerMargin, wrapperSize, options) { + var distance = current - start; + var speed = Math.abs(distance) / time; + + var deceleration = options.deceleration, + itemHeight = options.itemHeight, + swipeBounceTime = options.swipeBounceTime, + wheel = options.wheel, + swipeTime = options.swipeTime; + + var duration = swipeTime; + var rate = wheel ? 4 : 15; + + var destination = current + speed / deceleration * (distance < 0 ? -1 : 1); + + if (wheel && itemHeight) { + destination = Math.round(destination / itemHeight) * itemHeight; + } + + if (destination < lowerMargin) { + destination = wrapperSize ? lowerMargin - wrapperSize / rate * speed : lowerMargin; + duration = swipeBounceTime; + } else if (destination > 0) { + destination = wrapperSize ? wrapperSize / rate * speed : 0; + duration = swipeBounceTime; + } + + return { + destination: Math.round(destination), + duration: duration + }; +} + +var DEFAULT_INTERVAL = 100 / 60; + +var requestAnimationFrame = function () { + return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || + // if all else fails, use setTimeout + function (callback) { + return window.setTimeout(callback, (callback.interval || DEFAULT_INTERVAL) / 2); // make interval as precise as possible. + }; +}(); + +var cancelAnimationFrame = function () { + return window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || function (id) { + window.clearTimeout(id); + }; +}(); + +function coreMixin(BScroll) { + BScroll.prototype._start = function (e) { + var _eventType = eventType[e.type]; + if (_eventType !== TOUCH_EVENT) { + if (e.button !== 0) { + return; + } + } + if (!this.enabled || this.destroyed || this.initiated && this.initiated !== _eventType) { + return; + } + this.initiated = _eventType; + + if (this.options.preventDefault && !preventDefaultException(e.target, this.options.preventDefaultException)) { + e.preventDefault(); + } + + this.moved = false; + this.distX = 0; + this.distY = 0; + this.directionX = 0; + this.directionY = 0; + this.movingDirectionX = 0; + this.movingDirectionY = 0; + this.directionLocked = 0; + + this._transitionTime(); + this.startTime = getNow(); + + if (this.options.wheel) { + this.target = e.target; + } + + this.stop(); + + var point = e.touches ? e.touches[0] : e; + + this.startX = this.x; + this.startY = this.y; + this.absStartX = this.x; + this.absStartY = this.y; + this.pointX = point.pageX; + this.pointY = point.pageY; + + this.trigger('beforeScrollStart'); + }; + + BScroll.prototype._move = function (e) { + if (!this.enabled || this.destroyed || eventType[e.type] !== this.initiated) { + return; + } + + if (this.options.preventDefault) { + e.preventDefault(); + } + + var point = e.touches ? e.touches[0] : e; + var deltaX = point.pageX - this.pointX; + var deltaY = point.pageY - this.pointY; + + this.pointX = point.pageX; + this.pointY = point.pageY; + + this.distX += deltaX; + this.distY += deltaY; + + var absDistX = Math.abs(this.distX); + var absDistY = Math.abs(this.distY); + + var timestamp = getNow(); + + // We need to move at least momentumLimitDistance pixels for the scrolling to initiate + if (timestamp - this.endTime > this.options.momentumLimitTime && absDistY < this.options.momentumLimitDistance && absDistX < this.options.momentumLimitDistance) { + return; + } + + // If you are scrolling in one direction lock the other + if (!this.directionLocked && !this.options.freeScroll) { + if (absDistX > absDistY + this.options.directionLockThreshold) { + this.directionLocked = 'h'; // lock horizontally + } else if (absDistY >= absDistX + this.options.directionLockThreshold) { + this.directionLocked = 'v'; // lock vertically + } else { + this.directionLocked = 'n'; // no lock + } + } + + if (this.directionLocked === 'h') { + if (this.options.eventPassthrough === 'vertical') { + e.preventDefault(); + } else if (this.options.eventPassthrough === 'horizontal') { + this.initiated = false; + return; + } + deltaY = 0; + } else if (this.directionLocked === 'v') { + if (this.options.eventPassthrough === 'horizontal') { + e.preventDefault(); + } else if (this.options.eventPassthrough === 'vertical') { + this.initiated = false; + return; + } + deltaX = 0; + } + + deltaX = this.hasHorizontalScroll ? deltaX : 0; + deltaY = this.hasVerticalScroll ? deltaY : 0; + this.movingDirectionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0; + this.movingDirectionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0; + + var newX = this.x + deltaX; + var newY = this.y + deltaY; + + // Slow down or stop if outside of the boundaries + if (newX > 0 || newX < this.maxScrollX) { + if (this.options.bounce) { + newX = this.x + deltaX / 3; + } else { + newX = newX > 0 ? 0 : this.maxScrollX; + } + } + if (newY > 0 || newY < this.maxScrollY) { + if (this.options.bounce) { + newY = this.y + deltaY / 3; + } else { + newY = newY > 0 ? 0 : this.maxScrollY; + } + } + + if (!this.moved) { + this.moved = true; + this.trigger('scrollStart'); + } + + this._translate(newX, newY); + + if (timestamp - this.startTime > this.options.momentumLimitTime) { + this.startTime = timestamp; + this.startX = this.x; + this.startY = this.y; + + if (this.options.probeType === 1) { + this.trigger('scroll', { + x: this.x, + y: this.y + }); + } + } + + if (this.options.probeType > 1) { + this.trigger('scroll', { + x: this.x, + y: this.y + }); + } + + var scrollLeft = document.documentElement.scrollLeft || window.pageXOffset || document.body.scrollLeft; + var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; + + var pX = this.pointX - scrollLeft; + var pY = this.pointY - scrollTop; + + if (pX > document.documentElement.clientWidth - this.options.momentumLimitDistance || pX < this.options.momentumLimitDistance || pY < this.options.momentumLimitDistance || pY > document.documentElement.clientHeight - this.options.momentumLimitDistance) { + this._end(e); + } + }; + + BScroll.prototype._end = function (e) { + if (!this.enabled || this.destroyed || eventType[e.type] !== this.initiated) { + return; + } + this.initiated = false; + + if (this.options.preventDefault && !preventDefaultException(e.target, this.options.preventDefaultException)) { + e.preventDefault(); + } + + this.trigger('touchEnd', { + x: this.x, + y: this.y + }); + + var preventClick = this.stopFromTransition; + this.stopFromTransition = false; + + // if configure pull down refresh, check it first + if (this.options.pullDownRefresh && this._checkPullDown()) { + return; + } + + // reset if we are outside of the boundaries + if (this.resetPosition(this.options.bounceTime, ease.bounce)) { + return; + } + this.isInTransition = false; + // ensures that the last position is rounded + var newX = Math.round(this.x); + var newY = Math.round(this.y); + + // we scrolled less than 15 pixels + if (!this.moved) { + if (this.options.wheel) { + if (this.target && this.target.className === this.options.wheel.wheelWrapperClass) { + var index = Math.abs(Math.round(newY / this.itemHeight)); + var _offset = Math.round((this.pointY + offset(this.target).top - this.itemHeight / 2) / this.itemHeight); + this.target = this.items[index + _offset]; + } + this.scrollToElement(this.target, this.options.wheel.adjustTime || 400, true, true, ease.swipe); + } else { + if (!preventClick) { + if (this.options.tap) { + tap(e, this.options.tap); + } + + if (this.options.click) { + click(e); + } + } + } + this.trigger('scrollCancel'); + return; + } + + this.scrollTo(newX, newY); + + var deltaX = newX - this.absStartX; + var deltaY = newY - this.absStartY; + this.directionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0; + this.directionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0; + + this.endTime = getNow(); + + var duration = this.endTime - this.startTime; + var absDistX = Math.abs(newX - this.startX); + var absDistY = Math.abs(newY - this.startY); + + // flick + if (this._events.flick && duration < this.options.flickLimitTime && absDistX < this.options.flickLimitDistance && absDistY < this.options.flickLimitDistance) { + this.trigger('flick'); + return; + } + + var time = 0; + // start momentum animation if needed + if (this.options.momentum && duration < this.options.momentumLimitTime && (absDistY > this.options.momentumLimitDistance || absDistX > this.options.momentumLimitDistance)) { + var momentumX = this.hasHorizontalScroll ? momentum(this.x, this.startX, duration, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options) : { destination: newX, duration: 0 }; + var momentumY = this.hasVerticalScroll ? momentum(this.y, this.startY, duration, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options) : { destination: newY, duration: 0 }; + newX = momentumX.destination; + newY = momentumY.destination; + time = Math.max(momentumX.duration, momentumY.duration); + this.isInTransition = true; + } else { + if (this.options.wheel) { + newY = Math.round(newY / this.itemHeight) * this.itemHeight; + time = this.options.wheel.adjustTime || 400; + } + } + + var easing = ease.swipe; + if (this.options.snap) { + var snap = this._nearestSnap(newX, newY); + this.currentPage = snap; + time = this.options.snapSpeed || Math.max(Math.max(Math.min(Math.abs(newX - snap.x), 1000), Math.min(Math.abs(newY - snap.y), 1000)), 300); + newX = snap.x; + newY = snap.y; + + this.directionX = 0; + this.directionY = 0; + easing = ease.bounce; + } + + if (newX !== this.x || newY !== this.y) { + // change easing function when scroller goes out of the boundaries + if (newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY) { + easing = ease.swipeBounce; + } + this.scrollTo(newX, newY, time, easing); + return; + } + + if (this.options.wheel) { + this.selectedIndex = Math.round(Math.abs(this.y / this.itemHeight)); + } + this.trigger('scrollEnd', { + x: this.x, + y: this.y + }); + }; + + BScroll.prototype._resize = function () { + var _this = this; + + if (!this.enabled) { + return; + } + + clearTimeout(this.resizeTimeout); + this.resizeTimeout = setTimeout(function () { + _this.refresh(); + }, this.options.resizePolling); + }; + + BScroll.prototype._startProbe = function () { + cancelAnimationFrame(this.probeTimer); + this.probeTimer = requestAnimationFrame(probe); + + var me = this; + + function probe() { + if (!me.isInTransition) { + return; + } + var pos = me.getComputedPosition(); + me.trigger('scroll', pos); + me.probeTimer = requestAnimationFrame(probe); + } + }; + + BScroll.prototype._transitionProperty = function () { + var property = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'transform'; + + this.scrollerStyle[style.transitionProperty] = property; + }; + + BScroll.prototype._transitionTime = function () { + var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + + this.scrollerStyle[style.transitionDuration] = time + 'ms'; + + if (this.options.wheel) { + for (var i = 0; i < this.items.length; i++) { + this.items[i].style[style.transitionDuration] = time + 'ms'; + } + } + + if (this.indicators) { + for (var _i = 0; _i < this.indicators.length; _i++) { + this.indicators[_i].transitionTime(time); + } + } + }; + + BScroll.prototype._transitionTimingFunction = function (easing) { + this.scrollerStyle[style.transitionTimingFunction] = easing; + + if (this.options.wheel) { + for (var i = 0; i < this.items.length; i++) { + this.items[i].style[style.transitionTimingFunction] = easing; + } + } + + if (this.indicators) { + for (var _i2 = 0; _i2 < this.indicators.length; _i2++) { + this.indicators[_i2].transitionTimingFunction(easing); + } + } + }; + + BScroll.prototype._transitionEnd = function (e) { + if (e.target !== this.scroller || !this.isInTransition) { + return; + } + + this._transitionTime(); + if (!this.pulling && !this.resetPosition(this.options.bounceTime, ease.bounce)) { + this.isInTransition = false; + this.trigger('scrollEnd', { + x: this.x, + y: this.y + }); + } + }; + + BScroll.prototype._translate = function (x, y) { + if (this.options.useTransform) { + this.scrollerStyle[style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.translateZ; + } else { + x = Math.round(x); + y = Math.round(y); + this.scrollerStyle.left = x + 'px'; + this.scrollerStyle.top = y + 'px'; + } + + if (this.options.wheel) { + var _options$wheel$rotate = this.options.wheel.rotate, + rotate = _options$wheel$rotate === undefined ? 25 : _options$wheel$rotate; + + for (var i = 0; i < this.items.length; i++) { + var deg = rotate * (y / this.itemHeight + i); + this.items[i].style[style.transform] = 'rotateX(' + deg + 'deg)'; + } + } + + this.x = x; + this.y = y; + + if (this.indicators) { + for (var _i3 = 0; _i3 < this.indicators.length; _i3++) { + this.indicators[_i3].updatePosition(); + } + } + }; + + BScroll.prototype._animate = function (destX, destY, duration, easingFn) { + var me = this; + var startX = this.x; + var startY = this.y; + var startTime = getNow(); + var destTime = startTime + duration; + + function step() { + var now = getNow(); + + if (now >= destTime) { + me.isAnimating = false; + me._translate(destX, destY); + + if (!me.pulling && !me.resetPosition(me.options.bounceTime)) { + me.trigger('scrollEnd', { + x: me.x, + y: me.y + }); + } + return; + } + now = (now - startTime) / duration; + var easing = easingFn(now); + var newX = (destX - startX) * easing + startX; + var newY = (destY - startY) * easing + startY; + + me._translate(newX, newY); + + if (me.isAnimating) { + me.animateTimer = requestAnimationFrame(step); + } + + if (me.options.probeType === 3) { + me.trigger('scroll', { + x: me.x, + y: me.y + }); + } + } + + this.isAnimating = true; + cancelAnimationFrame(this.animateTimer); + step(); + }; + + BScroll.prototype.scrollBy = function (x, y) { + var time = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var easing = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ease.bounce; + + x = this.x + x; + y = this.y + y; + + this.scrollTo(x, y, time, easing); + }; + + BScroll.prototype.scrollTo = function (x, y) { + var time = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var easing = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ease.bounce; + + this.isInTransition = this.options.useTransition && time > 0 && (x !== this.x || y !== this.y); + + if (!time || this.options.useTransition) { + this._transitionProperty(); + this._transitionTimingFunction(easing.style); + this._transitionTime(time); + this._translate(x, y); + + if (time && this.options.probeType === 3) { + this._startProbe(); + } + + if (this.options.wheel) { + if (y > 0) { + this.selectedIndex = 0; + } else if (y < this.maxScrollY) { + this.selectedIndex = this.items.length - 1; + } else { + this.selectedIndex = Math.round(Math.abs(y / this.itemHeight)); + } + } + } else { + this._animate(x, y, time, easing.fn); + } + }; + + BScroll.prototype.scrollToElement = function (el, time, offsetX, offsetY, easing) { + if (!el) { + return; + } + el = el.nodeType ? el : this.scroller.querySelector(el); + + if (this.options.wheel && el.className !== this.options.wheel.wheelItemClass) { + return; + } + + var pos = offset(el); + pos.left -= this.wrapperOffset.left; + pos.top -= this.wrapperOffset.top; + + // if offsetX/Y are true we center the element to the screen + if (offsetX === true) { + offsetX = Math.round(el.offsetWidth / 2 - this.wrapper.offsetWidth / 2); + } + if (offsetY === true) { + offsetY = Math.round(el.offsetHeight / 2 - this.wrapper.offsetHeight / 2); + } + + pos.left -= offsetX || 0; + pos.top -= offsetY || 0; + pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left; + pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top; + + if (this.options.wheel) { + pos.top = Math.round(pos.top / this.itemHeight) * this.itemHeight; + } + + this.scrollTo(pos.left, pos.top, time, easing); + }; + + BScroll.prototype.resetPosition = function () { + var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var easeing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ease.bounce; + + var x = this.x; + if (!this.hasHorizontalScroll || x > 0) { + x = 0; + } else if (x < this.maxScrollX) { + x = this.maxScrollX; + } + + var y = this.y; + if (!this.hasVerticalScroll || y > 0) { + y = 0; + } else if (y < this.maxScrollY) { + y = this.maxScrollY; + } + + if (x === this.x && y === this.y) { + return false; + } + + this.scrollTo(x, y, time, easeing); + + return true; + }; + + BScroll.prototype.getComputedPosition = function () { + var matrix = window.getComputedStyle(this.scroller, null); + var x = void 0; + var y = void 0; + + if (this.options.useTransform) { + matrix = matrix[style.transform].split(')')[0].split(', '); + x = +(matrix[12] || matrix[4]); + y = +(matrix[13] || matrix[5]); + } else { + x = +matrix.left.replace(/[^-\d.]/g, ''); + y = +matrix.top.replace(/[^-\d.]/g, ''); + } + + return { + x: x, + y: y + }; + }; + + BScroll.prototype.stop = function () { + if (this.options.useTransition && this.isInTransition) { + this.isInTransition = false; + var pos = this.getComputedPosition(); + this._translate(pos.x, pos.y); + if (this.options.wheel) { + this.target = this.items[Math.round(-pos.y / this.itemHeight)]; + } else { + this.trigger('scrollEnd', { + x: this.x, + y: this.y + }); + } + this.stopFromTransition = true; + } else if (!this.options.useTransition && this.isAnimating) { + this.isAnimating = false; + this.trigger('scrollEnd', { + x: this.x, + y: this.y + }); + this.stopFromTransition = true; + } + }; + + BScroll.prototype.destroy = function () { + this._removeDOMEvents(); + // remove custom events + this._events = {}; + + if (this.options.scrollbar) { + this._removeScrollBars(); + } + + this.destroyed = true; + this.trigger('destroy'); + }; +} + +function snapMixin(BScroll) { + BScroll.prototype._initSnap = function () { + var _this = this; + + this.currentPage = {}; + var snap = this.options.snap; + + if (snap.loop) { + var children = this.scroller.children; + if (children.length > 0) { + prepend(children[children.length - 1].cloneNode(true), this.scroller); + this.scroller.appendChild(children[1].cloneNode(true)); + } + } + + var el = snap.el; + if (typeof el === 'string') { + el = this.scroller.querySelectorAll(el); + } + + this.on('refresh', function () { + _this.pages = []; + + if (!_this.wrapperWidth || !_this.wrapperHeight || !_this.scrollerWidth || !_this.scrollerHeight) { + return; + } + + var stepX = snap.stepX || _this.wrapperWidth; + var stepY = snap.stepY || _this.wrapperHeight; + + var x = 0; + var y = void 0; + var cx = void 0; + var cy = void 0; + var i = 0; + var l = void 0; + var m = 0; + var n = void 0; + var rect = void 0; + if (!el) { + cx = Math.round(stepX / 2); + cy = Math.round(stepY / 2); + + while (x > -_this.scrollerWidth) { + _this.pages[i] = []; + l = 0; + y = 0; + + while (y > -_this.scrollerHeight) { + _this.pages[i][l] = { + x: Math.max(x, _this.maxScrollX), + y: Math.max(y, _this.maxScrollY), + width: stepX, + height: stepY, + cx: x - cx, + cy: y - cy + }; + + y -= stepY; + l++; + } + + x -= stepX; + i++; + } + } else { + l = el.length; + n = -1; + + for (; i < l; i++) { + rect = getRect(el[i]); + if (i === 0 || rect.left <= getRect(el[i - 1]).left) { + m = 0; + n++; + } + + if (!_this.pages[m]) { + _this.pages[m] = []; + } + + x = Math.max(-rect.left, _this.maxScrollX); + y = Math.max(-rect.top, _this.maxScrollY); + cx = x - Math.round(rect.width / 2); + cy = y - Math.round(rect.height / 2); + + _this.pages[m][n] = { + x: x, + y: y, + width: rect.width, + height: rect.height, + cx: cx, + cy: cy + }; + + if (x > _this.maxScrollX) { + m++; + } + } + } + + var initPage = snap.loop ? 1 : 0; + _this.goToPage(_this.currentPage.pageX || initPage, _this.currentPage.pageY || 0, 0); + + // Update snap threshold if needed + var snapThreshold = snap.threshold; + if (snapThreshold % 1 === 0) { + _this.snapThresholdX = snapThreshold; + _this.snapThresholdY = snapThreshold; + } else { + _this.snapThresholdX = Math.round(_this.pages[_this.currentPage.pageX][_this.currentPage.pageY].width * snapThreshold); + _this.snapThresholdY = Math.round(_this.pages[_this.currentPage.pageX][_this.currentPage.pageY].height * snapThreshold); + } + }); + + this.on('scrollEnd', function () { + if (snap.loop) { + if (_this.currentPage.pageX === 0) { + _this.goToPage(_this.pages.length - 2, _this.currentPage.pageY, 0); + } + if (_this.currentPage.pageX === _this.pages.length - 1) { + _this.goToPage(1, _this.currentPage.pageY, 0); + } + } + }); + + if (snap.listenFlick !== false) { + this.on('flick', function () { + var time = snap.speed || Math.max(Math.max(Math.min(Math.abs(_this.x - _this.startX), 1000), Math.min(Math.abs(_this.y - _this.startY), 1000)), 300); + + _this.goToPage(_this.currentPage.pageX + _this.directionX, _this.currentPage.pageY + _this.directionY, time); + }); + } + }; + + BScroll.prototype._nearestSnap = function (x, y) { + if (!this.pages.length) { + return { x: 0, y: 0, pageX: 0, pageY: 0 }; + } + + var i = 0; + // Check if we exceeded the snap threshold + if (Math.abs(x - this.absStartX) <= this.snapThresholdX && Math.abs(y - this.absStartY) <= this.snapThresholdY) { + return this.currentPage; + } + + if (x > 0) { + x = 0; + } else if (x < this.maxScrollX) { + x = this.maxScrollX; + } + + if (y > 0) { + y = 0; + } else if (y < this.maxScrollY) { + y = this.maxScrollY; + } + + var l = this.pages.length; + for (; i < l; i++) { + if (x >= this.pages[i][0].cx) { + x = this.pages[i][0].x; + break; + } + } + + l = this.pages[i].length; + + var m = 0; + for (; m < l; m++) { + if (y >= this.pages[0][m].cy) { + y = this.pages[0][m].y; + break; + } + } + + if (i === this.currentPage.pageX) { + i += this.directionX; + + if (i < 0) { + i = 0; + } else if (i >= this.pages.length) { + i = this.pages.length - 1; + } + + x = this.pages[i][0].x; + } + + if (m === this.currentPage.pageY) { + m += this.directionY; + + if (m < 0) { + m = 0; + } else if (m >= this.pages[0].length) { + m = this.pages[0].length - 1; + } + + y = this.pages[0][m].y; + } + + return { + x: x, + y: y, + pageX: i, + pageY: m + }; + }; + + BScroll.prototype.goToPage = function (x, y, time) { + var easing = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ease.bounce; + + var snap = this.options.snap; + if (x >= this.pages.length) { + x = this.pages.length - 1; + } else if (x < 0) { + x = 0; + } + + if (y >= this.pages[x].length) { + y = this.pages[x].length - 1; + } else if (y < 0) { + y = 0; + } + + var posX = this.pages[x][y].x; + var posY = this.pages[x][y].y; + + time = time === undefined ? snap.speed || Math.max(Math.max(Math.min(Math.abs(posX - this.x), 1000), Math.min(Math.abs(posY - this.y), 1000)), 300) : time; + + this.currentPage = { + x: posX, + y: posY, + pageX: x, + pageY: y + }; + this.scrollTo(posX, posY, time, easing); + }; + + BScroll.prototype.next = function (time, easing) { + var x = this.currentPage.pageX; + var y = this.currentPage.pageY; + + x++; + if (x >= this.pages.length && this.hasVerticalScroll) { + x = 0; + y++; + } + + this.goToPage(x, y, time, easing); + }; + + BScroll.prototype.prev = function (time, easing) { + var x = this.currentPage.pageX; + var y = this.currentPage.pageY; + + x--; + if (x < 0 && this.hasVerticalScroll) { + x = 0; + y--; + } + + this.goToPage(x, y, time, easing); + }; + + BScroll.prototype.getCurrentPage = function () { + return this.options.snap && this.currentPage; + }; +} + +function warn(msg) { + console.error("[BScroll warn]: " + msg); +} + +function wheelMixin(BScroll) { + BScroll.prototype.wheelTo = function (index) { + if (this.options.wheel) { + this.y = -index * this.itemHeight; + this.scrollTo(0, this.y); + } + }; + + BScroll.prototype.getSelectedIndex = function () { + return this.options.wheel && this.selectedIndex; + }; + + BScroll.prototype._initWheel = function () { + var wheel = this.options.wheel; + if (!wheel.wheelWrapperClass) { + wheel.wheelWrapperClass = 'wheel-scroll'; + } + if (!wheel.wheelItemClass) { + wheel.wheelItemClass = 'wheel-item'; + } + if (wheel.selectedIndex === undefined) { + wheel.selectedIndex = 0; + warn('wheel option selectedIndex is required!'); + } + }; +} + +var INDICATOR_MIN_LEN = 8; + +function scrollbarMixin(BScroll) { + BScroll.prototype._initScrollbar = function () { + var _this = this; + + var _options$scrollbar$fa = this.options.scrollbar.fade, + fade = _options$scrollbar$fa === undefined ? true : _options$scrollbar$fa; + + this.indicators = []; + var indicator = void 0; + + if (this.options.scrollX) { + indicator = { + el: createScrollbar('horizontal'), + direction: 'horizontal', + fade: fade + }; + this._insertScrollBar(indicator.el); + + this.indicators.push(new Indicator(this, indicator)); + } + + if (this.options.scrollY) { + indicator = { + el: createScrollbar('vertical'), + direction: 'vertical', + fade: fade + }; + this._insertScrollBar(indicator.el); + this.indicators.push(new Indicator(this, indicator)); + } + + this.on('refresh', function () { + for (var i = 0; i < _this.indicators.length; i++) { + _this.indicators[i].refresh(); + } + }); + + if (fade) { + this.on('scrollEnd', function () { + for (var i = 0; i < _this.indicators.length; i++) { + _this.indicators[i].fade(); + } + }); + + this.on('scrollCancel', function () { + for (var i = 0; i < _this.indicators.length; i++) { + _this.indicators[i].fade(); + } + }); + + this.on('scrollStart', function () { + for (var i = 0; i < _this.indicators.length; i++) { + _this.indicators[i].fade(true); + } + }); + + this.on('beforeScrollStart', function () { + for (var i = 0; i < _this.indicators.length; i++) { + _this.indicators[i].fade(true, true); + } + }); + } + }; + + BScroll.prototype._insertScrollBar = function (scrollbar) { + this.wrapper.appendChild(scrollbar); + }; + + BScroll.prototype._removeScrollBars = function () { + for (var i = 0; i < this.indicators.length; i++) { + var indicator = this.indicators[i]; + indicator.remove(); + } + }; +} + +function createScrollbar(direction) { + var scrollbar = document.createElement('div'); + var indicator = document.createElement('div'); + + scrollbar.style.cssText = 'position:absolute;z-index:9999;pointerEvents:none'; + indicator.style.cssText = 'box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px;'; + + indicator.className = 'bscroll-indicator'; + + if (direction === 'horizontal') { + scrollbar.style.cssText += ';height:7px;left:2px;right:2px;bottom:0'; + indicator.style.height = '100%'; + scrollbar.className = 'bscroll-horizontal-scrollbar'; + } else { + scrollbar.style.cssText += ';width:7px;bottom:2px;top:2px;right:1px'; + indicator.style.width = '100%'; + scrollbar.className = 'bscroll-vertical-scrollbar'; + } + + scrollbar.style.cssText += ';overflow:hidden'; + scrollbar.appendChild(indicator); + + return scrollbar; +} + +function Indicator(scroller, options) { + this.wrapper = options.el; + this.wrapperStyle = this.wrapper.style; + this.indicator = this.wrapper.children[0]; + this.indicatorStyle = this.indicator.style; + this.scroller = scroller; + this.direction = options.direction; + if (options.fade) { + this.visible = 0; + this.wrapperStyle.opacity = '0'; + } else { + this.visible = 1; + } +} + +Indicator.prototype.refresh = function () { + this.transitionTime(); + this._calculate(); + this.updatePosition(); +}; + +Indicator.prototype.fade = function (visible, hold) { + var _this2 = this; + + if (hold && !this.visible) { + return; + } + + var time = visible ? 250 : 500; + + visible = visible ? '1' : '0'; + + this.wrapperStyle[style.transitionDuration] = time + 'ms'; + + clearTimeout(this.fadeTimeout); + this.fadeTimeout = setTimeout(function () { + _this2.wrapperStyle.opacity = visible; + _this2.visible = +visible; + }, 0); +}; + +Indicator.prototype.updatePosition = function () { + if (this.direction === 'vertical') { + var y = Math.round(this.sizeRatioY * this.scroller.y); + + if (y < 0) { + this.transitionTime(500); + var height = Math.max(this.indicatorHeight + y * 3, INDICATOR_MIN_LEN); + this.indicatorStyle.height = height + 'px'; + y = 0; + } else if (y > this.maxPosY) { + this.transitionTime(500); + var _height = Math.max(this.indicatorHeight - (y - this.maxPosY) * 3, INDICATOR_MIN_LEN); + this.indicatorStyle.height = _height + 'px'; + y = this.maxPosY + this.indicatorHeight - _height; + } else { + this.indicatorStyle.height = this.indicatorHeight + 'px'; + } + this.y = y; + + if (this.scroller.options.useTransform) { + this.indicatorStyle[style.transform] = 'translateY(' + y + 'px)' + this.scroller.translateZ; + } else { + this.indicatorStyle.top = y + 'px'; + } + } else { + var x = Math.round(this.sizeRatioX * this.scroller.x); + + if (x < 0) { + this.transitionTime(500); + var width = Math.max(this.indicatorWidth + x * 3, INDICATOR_MIN_LEN); + this.indicatorStyle.width = width + 'px'; + x = 0; + } else if (x > this.maxPosX) { + this.transitionTime(500); + var _width = Math.max(this.indicatorWidth - (x - this.maxPosX) * 3, INDICATOR_MIN_LEN); + this.indicatorStyle.width = _width + 'px'; + x = this.maxPosX + this.indicatorWidth - _width; + } else { + this.indicatorStyle.width = this.indicatorWidth + 'px'; + } + + this.x = x; + + if (this.scroller.options.useTransform) { + this.indicatorStyle[style.transform] = 'translateX(' + x + 'px)' + this.scroller.translateZ; + } else { + this.indicatorStyle.left = x + 'px'; + } + } +}; + +Indicator.prototype.transitionTime = function () { + var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + + this.indicatorStyle[style.transitionDuration] = time + 'ms'; +}; + +Indicator.prototype.transitionTimingFunction = function (easing) { + this.indicatorStyle[style.transitionTimingFunction] = easing; +}; + +Indicator.prototype.remove = function () { + this.wrapper.parentNode.removeChild(this.wrapper); +}; + +Indicator.prototype._calculate = function () { + if (this.direction === 'vertical') { + var wrapperHeight = this.wrapper.clientHeight; + this.indicatorHeight = Math.max(Math.round(wrapperHeight * wrapperHeight / (this.scroller.scrollerHeight || wrapperHeight || 1)), INDICATOR_MIN_LEN); + this.indicatorStyle.height = this.indicatorHeight + 'px'; + + this.maxPosY = wrapperHeight - this.indicatorHeight; + + this.sizeRatioY = this.maxPosY / this.scroller.maxScrollY; + } else { + var wrapperWidth = this.wrapper.clientWidth; + this.indicatorWidth = Math.max(Math.round(wrapperWidth * wrapperWidth / (this.scroller.scrollerWidth || wrapperWidth || 1)), INDICATOR_MIN_LEN); + this.indicatorStyle.width = this.indicatorWidth + 'px'; + + this.maxPosX = wrapperWidth - this.indicatorWidth; + + this.sizeRatioX = this.maxPosX / this.scroller.maxScrollX; + } +}; + +function pullDownMixin(BScroll) { + BScroll.prototype._initPullDown = function () { + // must watch scroll in real time + this.options.probeType = 3; + }; + + BScroll.prototype._checkPullDown = function () { + var _options$pullDownRefr = this.options.pullDownRefresh, + _options$pullDownRefr2 = _options$pullDownRefr.threshold, + threshold = _options$pullDownRefr2 === undefined ? 90 : _options$pullDownRefr2, + _options$pullDownRefr3 = _options$pullDownRefr.stop, + stop = _options$pullDownRefr3 === undefined ? 40 : _options$pullDownRefr3; + + + if (this.y > threshold) { + if (!this.pulling) { + this.pulling = true; + this.trigger('pullingDown'); + } + this.scrollTo(this.x, stop, this.options.bounceTime, ease.bounce); + } + + return this.pulling; + }; + + BScroll.prototype.finishPullDown = function () { + this.pulling = false; + this.resetPosition(this.options.bounceTime, ease.bounce); + }; +} + +function pullUpMixin(BScroll) { + BScroll.prototype._initPullUp = function () { + // must watch scroll in real time + this.options.probeType = 3; + + this.pullupWatching = false; + this._watchPullUp(); + }; + + BScroll.prototype._watchPullUp = function () { + if (this.pullupWatching) { + return; + } + this.pullupWatching = true; + var _options$pullUpLoad$t = this.options.pullUpLoad.threshold, + threshold = _options$pullUpLoad$t === undefined ? 0 : _options$pullUpLoad$t; + + + this.on('scroll', checkToEnd); + + function checkToEnd(pos) { + if (this.movingDirectionY === 1 && pos.y <= this.maxScrollY + threshold) { + this.trigger('pullingUp'); + this.pullupWatching = false; + this.off('scroll', checkToEnd); + } + } + }; + + BScroll.prototype.finishPullUp = function () { + var _this = this; + + if (this.isInTransition) { + this.once('scrollEnd', function () { + _this._watchPullUp(); + }); + } else { + this._watchPullUp(); + } + }; +} + +function BScroll(el, options) { + this.wrapper = typeof el === 'string' ? document.querySelector(el) : el; + if (!this.wrapper) { + warn('can not resolve the wrapper dom'); + } + this.scroller = this.wrapper.children[0]; + if (!this.scroller) { + warn('the wrapper need at least one child element to be scroller'); + } + // cache style for better performance + this.scrollerStyle = this.scroller.style; + + this._init(el, options); +} + +initMixin(BScroll); +coreMixin(BScroll); +eventMixin(BScroll); +snapMixin(BScroll); +wheelMixin(BScroll); +scrollbarMixin(BScroll); +pullDownMixin(BScroll); +pullUpMixin(BScroll); + +BScroll.Version = '1.4.2'; + +export default BScroll; diff --git a/dist/bscroll.js b/dist/bscroll.js index 3eecb709..18bd9242 100644 --- a/dist/bscroll.js +++ b/dist/bscroll.js @@ -1,5 +1,5 @@ /*! - * better-normal-scroll v1.4.1 + * better-normal-scroll v1.4.2 * (c) 2016-2017 ustbhuangyi * Released under the MIT License. */ @@ -1901,7 +1901,7 @@ scrollbarMixin(BScroll); pullDownMixin(BScroll); pullUpMixin(BScroll); -BScroll.Version = '1.4.1'; +BScroll.Version = '1.4.2'; return BScroll; diff --git a/dist/bscroll.min.js b/dist/bscroll.min.js index 370106c4..5e03616c 100644 --- a/dist/bscroll.min.js +++ b/dist/bscroll.min.js @@ -1,6 +1,6 @@ /*! - * better-normal-scroll v1.4.1 + * better-normal-scroll v1.4.2 * (c) 2016-2017 ustbhuangyi * Released under the MIT License. */ -!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.BScroll=i()}(this,function(){"use strict";function t(t){return!1!==x&&("standard"===x?t:x+t.charAt(0).toUpperCase()+t.substr(1))}function i(t,i,e,s){t.addEventListener(i,e,{passive:!1,capture:!!s})}function e(t,i,e,s){t.removeEventListener(i,e,{passive:!1,capture:!!s})}function s(t){for(var i=0,e=0;t;)i-=t.offsetLeft,e-=t.offsetTop,t=t.offsetParent;return{left:i,top:e}}function o(t){if(t instanceof window.SVGElement){var i=t.getBoundingClientRect();return{top:i.top,left:i.left,width:i.width,height:i.height}}return{top:t.offsetTop,left:t.offsetLeft,width:t.offsetWidth,height:t.offsetHeight}}function n(t,i){for(var e in i)if(i[e].test(t[e]))return!0;return!1}function r(t,i){var e=document.createEvent("Event");e.initEvent(i,!0,!0),e.pageX=t.pageX,e.pageY=t.pageY,t.target.dispatchEvent(e)}function h(t){var i=t.target;if(!/(SELECT|INPUT|TEXTAREA)/i.test(i.tagName)){var e=document.createEvent(window.MouseEvent?"MouseEvents":"Event");e.initEvent("click",!0,!1),e._constructed=!0,i.dispatchEvent(e)}}function a(t,i){i.firstChild?l(t,i.firstChild):i.appendChild(t)}function l(t,i){i.parentNode.insertBefore(t,i)}function c(){return window.performance&&window.performance.now?window.performance.now()+window.performance.timing.navigationStart:+new Date}function p(t){for(var i=arguments.length,e=Array(i>1?i-1:0),s=1;s0&&(m=o?o/u*h:0,d=c),{destination:Math.round(m),duration:d}}function u(t){console.error("[BScroll warn]: "+t)}function m(t){var i=document.createElement("div"),e=document.createElement("div");return i.style.cssText="position:absolute;z-index:9999;pointerEvents:none",e.style.cssText="box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px;",e.className="bscroll-indicator","horizontal"===t?(i.style.cssText+=";height:7px;left:2px;right:2px;bottom:0",e.style.height="100%",i.className="bscroll-horizontal-scrollbar"):(i.style.cssText+=";width:7px;bottom:2px;top:2px;right:1px",e.style.width="100%",i.className="bscroll-vertical-scrollbar"),i.style.cssText+=";overflow:hidden",i.appendChild(e),i}function f(t,i){this.wrapper=i.el,this.wrapperStyle=this.wrapper.style,this.indicator=this.wrapper.children[0],this.indicatorStyle=this.indicator.style,this.scroller=t,this.direction=i.direction,i.fade?(this.visible=0,this.wrapperStyle.opacity="0"):this.visible=1}function g(t,i){this.wrapper="string"==typeof t?document.querySelector(t):t,this.wrapper||u("can not resolve the wrapper dom"),this.scroller=this.wrapper.children[0],this.scroller||u("the wrapper need at least one child element to be scroller"),this.scrollerStyle=this.scroller.style,this._init(t,i)}var v=function(){function t(t,i){var e=[],s=!0,o=!1,n=void 0;try{for(var r,h=t[Symbol.iterator]();!(s=(r=h.next()).done)&&(e.push(r.value),!i||e.length!==i);s=!0);}catch(t){o=!0,n=t}finally{try{!s&&h.return&&h.return()}finally{if(o)throw n}}return e}return function(i,e){if(Array.isArray(i))return i;if(Symbol.iterator in Object(i))return t(i,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),y=function(t){if(Array.isArray(t)){for(var i=0,e=Array(t.length);ithis.maxPosY){this.transitionTime(500);var e=Math.max(this.indicatorHeight-3*(t-this.maxPosY),8);this.indicatorStyle.height=e+"px",t=this.maxPosY+this.indicatorHeight-e}else this.indicatorStyle.height=this.indicatorHeight+"px";this.y=t,this.scroller.options.useTransform?this.indicatorStyle[X.transform]="translateY("+t+"px)"+this.scroller.translateZ:this.indicatorStyle.top=t+"px"}else{var s=Math.round(this.sizeRatioX*this.scroller.x);if(s<0){this.transitionTime(500);var o=Math.max(this.indicatorWidth+3*s,8);this.indicatorStyle.width=o+"px",s=0}else if(s>this.maxPosX){this.transitionTime(500);var n=Math.max(this.indicatorWidth-3*(s-this.maxPosX),8);this.indicatorStyle.width=n+"px",s=this.maxPosX+this.indicatorWidth-n}else this.indicatorStyle.width=this.indicatorWidth+"px";this.x=s,this.scroller.options.useTransform?this.indicatorStyle[X.transform]="translateX("+s+"px)"+this.scroller.translateZ:this.indicatorStyle.left=s+"px"}},f.prototype.transitionTime=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.indicatorStyle[X.transitionDuration]=t+"ms"},f.prototype.transitionTimingFunction=function(t){this.indicatorStyle[X.transitionTimingFunction]=t},f.prototype.remove=function(){this.wrapper.parentNode.removeChild(this.wrapper)},f.prototype._calculate=function(){if("vertical"===this.direction){var t=this.wrapper.clientHeight;this.indicatorHeight=Math.max(Math.round(t*t/(this.scroller.scrollerHeight||t||1)),8),this.indicatorStyle.height=this.indicatorHeight+"px",this.maxPosY=t-this.indicatorHeight,this.sizeRatioY=this.maxPosY/this.scroller.maxScrollY}else{var i=this.wrapper.clientWidth;this.indicatorWidth=Math.max(Math.round(i*i/(this.scroller.scrollerWidth||i||1)),8),this.indicatorStyle.width=this.indicatorWidth+"px",this.maxPosX=i-this.indicatorWidth,this.sizeRatioX=this.maxPosX/this.scroller.maxScrollX}},function(t){t.prototype._init=function(t,i){this._handleOptions(i),this._events={},this.x=0,this.y=0,this.directionX=0,this.directionY=0,this._addDOMEvents(),this._initExtFeatures(),this._watchTransition(),this.refresh(),this.options.snap||this.scrollTo(this.options.startX,this.options.startY),this.enable()},t.prototype._handleOptions=function(t){this.options=p({},E,t),this.translateZ=this.options.HWCompositing&&b?" translateZ(0)":"",this.options.useTransition=this.options.useTransition&&Y,this.options.useTransform=this.options.useTransform&&P,this.options.preventDefault=!this.options.eventPassthrough&&this.options.preventDefault,this.options.scrollX="horizontal"!==this.options.eventPassthrough&&this.options.scrollX,this.options.scrollY="vertical"!==this.options.eventPassthrough&&this.options.scrollY,this.options.freeScroll=this.options.freeScroll&&!this.options.eventPassthrough,this.options.directionLockThreshold=this.options.eventPassthrough?0:this.options.directionLockThreshold,!0===this.options.tap&&(this.options.tap="tap")},t.prototype._addDOMEvents=function(){var t=i;this._handleDOMEvents(t)},t.prototype._removeDOMEvents=function(){var t=e;this._handleDOMEvents(t)},t.prototype._handleDOMEvents=function(t){var i=this.options.bindToWrapper?this.wrapper:window;t(window,"orientationchange",this),t(window,"resize",this),this.options.click&&t(this.wrapper,"click",this,!0),this.options.disableMouse||(t(this.wrapper,"mousedown",this),t(i,"mousemove",this),t(i,"mousecancel",this),t(i,"mouseup",this)),S&&!this.options.disableTouch&&(t(this.wrapper,"touchstart",this),t(i,"touchmove",this),t(i,"touchcancel",this),t(i,"touchend",this)),t(this.scroller,X.transitionEnd,this)},t.prototype._initExtFeatures=function(){this.options.snap&&this._initSnap(),this.options.scrollbar&&this._initScrollbar(),this.options.pullUpLoad&&this._initPullUp(),this.options.pullDownRefresh&&this._initPullDown(),this.options.wheel&&this._initWheel()},t.prototype.handleEvent=function(t){switch(t.type){case"touchstart":case"mousedown":this._start(t);break;case"touchmove":case"mousemove":this._move(t);break;case"touchend":case"mouseup":case"touchcancel":case"mousecancel":this._end(t);break;case"orientationchange":case"resize":this._resize();break;case"transitionend":case"webkitTransitionEnd":case"oTransitionEnd":case"MSTransitionEnd":this._transitionEnd(t);break;case"click":this.enabled&&!t._constructed&&(n(t.target,this.options.preventDefaultException)||t.preventDefault(),t.stopPropagation())}},t.prototype.refresh=function(){var t=o(this.wrapper);this.wrapperWidth=t.width,this.wrapperHeight=t.height;var i=o(this.scroller);this.scrollerWidth=i.width,this.scrollerHeight=i.height;var e=this.options.wheel;e?(this.items=this.scroller.children,this.options.itemHeight=this.itemHeight=this.items.length?this.scrollerHeight/this.items.length:0,void 0===this.selectedIndex&&(this.selectedIndex=e.selectedIndex||0),this.options.startY=-this.selectedIndex*this.itemHeight,this.maxScrollX=0,this.maxScrollY=-this.itemHeight*(this.items.length-1)):(this.maxScrollX=this.wrapperWidth-this.scrollerWidth,this.maxScrollY=this.wrapperHeight-this.scrollerHeight),this.hasHorizontalScroll=this.options.scrollX&&this.maxScrollX<0,this.hasVerticalScroll=this.options.scrollY&&this.maxScrollY<0,this.hasHorizontalScroll||(this.maxScrollX=0,this.scrollerWidth=this.wrapperWidth),this.hasVerticalScroll||(this.maxScrollY=0,this.scrollerHeight=this.wrapperHeight),this.endTime=0,this.directionX=0,this.directionY=0,this.wrapperOffset=s(this.wrapper),this.trigger("refresh"),this.resetPosition()},t.prototype.enable=function(){this.enabled=!0},t.prototype.disable=function(){this.enabled=!1},t.prototype._watchTransition=function(){var t=!1,i=this,e=this.scroller.style.pointerEvents||"auto";Object.defineProperty(this,"isInTransition",{get:function(){return t},set:function(s){t=s,i.scroller.style.pointerEvents=t?"none":e}})}}(g),function(t){t.prototype._start=function(t){var i=M[t.type];if((i===_||0===t.button)&&!(!this.enabled||this.destroyed||this.initiated&&this.initiated!==i)){this.initiated=i,this.options.preventDefault&&!n(t.target,this.options.preventDefaultException)&&t.preventDefault(),this.moved=!1,this.distX=0,this.distY=0,this.directionX=0,this.directionY=0,this.movingDirectionX=0,this.movingDirectionY=0,this.directionLocked=0,this._transitionTime(),this.startTime=c(),this.options.wheel&&(this.target=t.target),this.stop();var e=t.touches?t.touches[0]:t;this.startX=this.x,this.startY=this.y,this.absStartX=this.x,this.absStartY=this.y,this.pointX=e.pageX,this.pointY=e.pageY,this.trigger("beforeScrollStart")}},t.prototype._move=function(t){if(this.enabled&&!this.destroyed&&M[t.type]===this.initiated){this.options.preventDefault&&t.preventDefault();var i=t.touches?t.touches[0]:t,e=i.pageX-this.pointX,s=i.pageY-this.pointY;this.pointX=i.pageX,this.pointY=i.pageY,this.distX+=e,this.distY+=s;var o=Math.abs(this.distX),n=Math.abs(this.distY),r=c();if(!(r-this.endTime>this.options.momentumLimitTime&&nn+this.options.directionLockThreshold?this.directionLocked="h":n>=o+this.options.directionLockThreshold?this.directionLocked="v":this.directionLocked="n"),"h"===this.directionLocked){if("vertical"===this.options.eventPassthrough)t.preventDefault();else if("horizontal"===this.options.eventPassthrough)return void(this.initiated=!1);s=0}else if("v"===this.directionLocked){if("horizontal"===this.options.eventPassthrough)t.preventDefault();else if("vertical"===this.options.eventPassthrough)return void(this.initiated=!1);e=0}e=this.hasHorizontalScroll?e:0,s=this.hasVerticalScroll?s:0,this.movingDirectionX=e>0?-1:e<0?1:0,this.movingDirectionY=s>0?-1:s<0?1:0;var h=this.x+e,a=this.y+s;(h>0||h0?0:this.maxScrollX),(a>0||a0?0:this.maxScrollY),this.moved||(this.moved=!0,this.trigger("scrollStart")),this._translate(h,a),r-this.startTime>this.options.momentumLimitTime&&(this.startTime=r,this.startX=this.x,this.startY=this.y,1===this.options.probeType&&this.trigger("scroll",{x:this.x,y:this.y})),this.options.probeType>1&&this.trigger("scroll",{x:this.x,y:this.y});var l=document.documentElement.scrollLeft||window.pageXOffset||document.body.scrollLeft,p=document.documentElement.scrollTop||window.pageYOffset||document.body.scrollTop,d=this.pointX-l,u=this.pointY-p;(d>document.documentElement.clientWidth-this.options.momentumLimitDistance||ddocument.documentElement.clientHeight-this.options.momentumLimitDistance)&&this._end(t)}}},t.prototype._end=function(t){if(this.enabled&&!this.destroyed&&M[t.type]===this.initiated){this.initiated=!1,this.options.preventDefault&&!n(t.target,this.options.preventDefaultException)&&t.preventDefault(),this.trigger("touchEnd",{x:this.x,y:this.y});var i=this.stopFromTransition;if(this.stopFromTransition=!1,!(this.options.pullDownRefresh&&this._checkPullDown()||this.resetPosition(this.options.bounceTime,D.bounce))){this.isInTransition=!1;var e=Math.round(this.x),o=Math.round(this.y);if(this.moved){this.scrollTo(e,o);var a=e-this.absStartX,l=o-this.absStartY;this.directionX=a>0?-1:a<0?1:0,this.directionY=l>0?-1:l<0?1:0,this.endTime=c();var p=this.endTime-this.startTime,u=Math.abs(e-this.startX),m=Math.abs(o-this.startY);if(this._events.flick&&pthis.options.momentumLimitDistance||u>this.options.momentumLimitDistance)){var g=this.hasHorizontalScroll?d(this.x,this.startX,p,this.maxScrollX,this.options.bounce?this.wrapperWidth:0,this.options):{destination:e,duration:0},v=this.hasVerticalScroll?d(this.y,this.startY,p,this.maxScrollY,this.options.bounce?this.wrapperHeight:0,this.options):{destination:o,duration:0};e=g.destination,o=v.destination,f=Math.max(g.duration,v.duration),this.isInTransition=!0}else this.options.wheel&&(o=Math.round(o/this.itemHeight)*this.itemHeight,f=this.options.wheel.adjustTime||400);var y=D.swipe;if(this.options.snap){var w=this._nearestSnap(e,o);this.currentPage=w,f=this.options.snapSpeed||Math.max(Math.max(Math.min(Math.abs(e-w.x),1e3),Math.min(Math.abs(o-w.y),1e3)),300),e=w.x,o=w.y,this.directionX=0,this.directionY=0,y=D.bounce}if(e!==this.x||o!==this.y)return(e>0||e0||o0&&void 0!==arguments[0]?arguments[0]:"transform";this.scrollerStyle[X.transitionProperty]=t},t.prototype._transitionTime=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(this.scrollerStyle[X.transitionDuration]=t+"ms",this.options.wheel)for(var i=0;i=l)return n.isAnimating=!1,n._translate(t,i),void(n.pulling||n.resetPosition(n.options.bounceTime)||n.trigger("scrollEnd",{x:n.x,y:n.y}));var d=s(p=(p-a)/e),u=(t-r)*d+r,m=(i-h)*d+h;n._translate(u,m),n.isAnimating&&(n.animateTimer=H(o)),3===n.options.probeType&&n.trigger("scroll",{x:n.x,y:n.y})}var n=this,r=this.x,h=this.y,a=c(),l=a+e;this.isAnimating=!0,k(this.animateTimer),o()},t.prototype.scrollBy=function(t,i){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D.bounce;t=this.x+t,i=this.y+i,this.scrollTo(t,i,e,s)},t.prototype.scrollTo=function(t,i){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D.bounce;this.isInTransition=this.options.useTransition&&e>0&&(t!==this.x||i!==this.y),!e||this.options.useTransition?(this._transitionProperty(),this._transitionTimingFunction(s.style),this._transitionTime(e),this._translate(t,i),e&&3===this.options.probeType&&this._startProbe(),this.options.wheel&&(i>0?this.selectedIndex=0:i0?0:r.left0?0:r.top0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:D.bounce,e=this.x;!this.hasHorizontalScroll||e>0?e=0:e0?s=0:s2&&void 0!==arguments[2]?arguments[2]:this;this._events[t]||(this._events[t]=[]),this._events[t].push([i,e])},t.prototype.once=function(t,i){function e(){this.off(t,e),o||(o=!0,i.apply(s,arguments))}var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this,o=!1;e.fn=i,this.on(t,e)},t.prototype.off=function(t,i){var e=this._events[t];if(e)for(var s=e.length;s--;)(e[s][0]===i||e[s][0]&&e[s][0].fn===i)&&(e[s][0]=void 0)},t.prototype.trigger=function(t){var i=this._events[t];if(i)for(var e=i.length,s=[].concat(y(i)),o=0;o0&&(a(e[e.length-1].cloneNode(!0),this.scroller),this.scroller.appendChild(e[1].cloneNode(!0)))}var s=i.el;"string"==typeof s&&(s=this.scroller.querySelectorAll(s)),this.on("refresh",function(){if(t.pages=[],t.wrapperWidth&&t.wrapperHeight&&t.scrollerWidth&&t.scrollerHeight){var e=i.stepX||t.wrapperWidth,n=i.stepY||t.wrapperHeight,r=0,h=void 0,a=void 0,l=void 0,c=0,p=void 0,d=0,u=void 0,m=void 0;if(s)for(p=s.length,u=-1;ct.maxScrollX&&d++;else for(a=Math.round(e/2),l=Math.round(n/2);r>-t.scrollerWidth;){for(t.pages[c]=[],p=0,h=0;h>-t.scrollerHeight;)t.pages[c][p]={x:Math.max(r,t.maxScrollX),y:Math.max(h,t.maxScrollY),width:e,height:n,cx:r-a,cy:h-l},h-=n,p++;r-=e,c++}var f=i.loop?1:0;t.goToPage(t.currentPage.pageX||f,t.currentPage.pageY||0,0);var g=i.threshold;g%1==0?(t.snapThresholdX=g,t.snapThresholdY=g):(t.snapThresholdX=Math.round(t.pages[t.currentPage.pageX][t.currentPage.pageY].width*g),t.snapThresholdY=Math.round(t.pages[t.currentPage.pageX][t.currentPage.pageY].height*g))}}),this.on("scrollEnd",function(){i.loop&&(0===t.currentPage.pageX&&t.goToPage(t.pages.length-2,t.currentPage.pageY,0),t.currentPage.pageX===t.pages.length-1&&t.goToPage(1,t.currentPage.pageY,0))}),!1!==i.listenFlick&&this.on("flick",function(){var e=i.speed||Math.max(Math.max(Math.min(Math.abs(t.x-t.startX),1e3),Math.min(Math.abs(t.y-t.startY),1e3)),300);t.goToPage(t.currentPage.pageX+t.directionX,t.currentPage.pageY+t.directionY,e)})},t.prototype._nearestSnap=function(t,i){if(!this.pages.length)return{x:0,y:0,pageX:0,pageY:0};var e=0;if(Math.abs(t-this.absStartX)<=this.snapThresholdX&&Math.abs(i-this.absStartY)<=this.snapThresholdY)return this.currentPage;t>0?t=0:t0?i=0:i=this.pages[e][0].cx){t=this.pages[e][0].x;break}s=this.pages[e].length;for(var o=0;o=this.pages[0][o].cy){i=this.pages[0][o].y;break}return e===this.currentPage.pageX&&((e+=this.directionX)<0?e=0:e>=this.pages.length&&(e=this.pages.length-1),t=this.pages[e][0].x),o===this.currentPage.pageY&&((o+=this.directionY)<0?o=0:o>=this.pages[0].length&&(o=this.pages[0].length-1),i=this.pages[0][o].y),{x:t,y:i,pageX:e,pageY:o}},t.prototype.goToPage=function(t,i,e){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D.bounce,o=this.options.snap;t>=this.pages.length?t=this.pages.length-1:t<0&&(t=0),i>=this.pages[t].length?i=this.pages[t].length-1:i<0&&(i=0);var n=this.pages[t][i].x,r=this.pages[t][i].y;e=void 0===e?o.speed||Math.max(Math.max(Math.min(Math.abs(n-this.x),1e3),Math.min(Math.abs(r-this.y),1e3)),300):e,this.currentPage={x:n,y:r,pageX:t,pageY:i},this.scrollTo(n,r,e,s)},t.prototype.next=function(t,i){var e=this.currentPage.pageX,s=this.currentPage.pageY;++e>=this.pages.length&&this.hasVerticalScroll&&(e=0,s++),this.goToPage(e,s,t,i)},t.prototype.prev=function(t,i){var e=this.currentPage.pageX,s=this.currentPage.pageY;--e<0&&this.hasVerticalScroll&&(e=0,s--),this.goToPage(e,s,t,i)},t.prototype.getCurrentPage=function(){return this.options.snap&&this.currentPage}}(g),function(t){t.prototype.wheelTo=function(t){this.options.wheel&&(this.y=-t*this.itemHeight,this.scrollTo(0,this.y))},t.prototype.getSelectedIndex=function(){return this.options.wheel&&this.selectedIndex},t.prototype._initWheel=function(){var t=this.options.wheel;t.wheelWrapperClass||(t.wheelWrapperClass="wheel-scroll"),t.wheelItemClass||(t.wheelItemClass="wheel-item"),void 0===t.selectedIndex&&(t.selectedIndex=0,u("wheel option selectedIndex is required!"))}}(g),function(t){t.prototype._initScrollbar=function(){var t=this,i=this.options.scrollbar.fade,e=void 0===i||i;this.indicators=[];var s=void 0;this.options.scrollX&&(s={el:m("horizontal"),direction:"horizontal",fade:e},this._insertScrollBar(s.el),this.indicators.push(new f(this,s))),this.options.scrollY&&(s={el:m("vertical"),direction:"vertical",fade:e},this._insertScrollBar(s.el),this.indicators.push(new f(this,s))),this.on("refresh",function(){for(var i=0;ie&&(this.pulling||(this.pulling=!0,this.trigger("pullingDown")),this.scrollTo(this.x,o,this.options.bounceTime,D.bounce)),this.pulling},t.prototype.finishPullDown=function(){this.pulling=!1,this.resetPosition(this.options.bounceTime,D.bounce)}}(g),function(t){t.prototype._initPullUp=function(){this.options.probeType=3,this.pullupWatching=!1,this._watchPullUp()},t.prototype._watchPullUp=function(){function t(i){1===this.movingDirectionY&&i.y<=this.maxScrollY+e&&(this.trigger("pullingUp"),this.pullupWatching=!1,this.off("scroll",t))}if(!this.pullupWatching){this.pullupWatching=!0;var i=this.options.pullUpLoad.threshold,e=void 0===i?0:i;this.on("scroll",t)}},t.prototype.finishPullUp=function(){var t=this;this.isInTransition?this.once("scrollEnd",function(){t._watchPullUp()}):this._watchPullUp()}}(g),g.Version="1.4.1",g}); \ No newline at end of file +!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.BScroll=i()}(this,function(){"use strict";function t(t){return!1!==x&&("standard"===x?t:x+t.charAt(0).toUpperCase()+t.substr(1))}function i(t,i,e,s){t.addEventListener(i,e,{passive:!1,capture:!!s})}function e(t,i,e,s){t.removeEventListener(i,e,{passive:!1,capture:!!s})}function s(t){for(var i=0,e=0;t;)i-=t.offsetLeft,e-=t.offsetTop,t=t.offsetParent;return{left:i,top:e}}function o(t){if(t instanceof window.SVGElement){var i=t.getBoundingClientRect();return{top:i.top,left:i.left,width:i.width,height:i.height}}return{top:t.offsetTop,left:t.offsetLeft,width:t.offsetWidth,height:t.offsetHeight}}function n(t,i){for(var e in i)if(i[e].test(t[e]))return!0;return!1}function r(t,i){var e=document.createEvent("Event");e.initEvent(i,!0,!0),e.pageX=t.pageX,e.pageY=t.pageY,t.target.dispatchEvent(e)}function h(t){var i=t.target;if(!/(SELECT|INPUT|TEXTAREA)/i.test(i.tagName)){var e=document.createEvent(window.MouseEvent?"MouseEvents":"Event");e.initEvent("click",!0,!1),e._constructed=!0,i.dispatchEvent(e)}}function a(t,i){i.firstChild?l(t,i.firstChild):i.appendChild(t)}function l(t,i){i.parentNode.insertBefore(t,i)}function c(){return window.performance&&window.performance.now?window.performance.now()+window.performance.timing.navigationStart:+new Date}function p(t){for(var i=arguments.length,e=Array(i>1?i-1:0),s=1;s0&&(m=o?o/u*h:0,d=c),{destination:Math.round(m),duration:d}}function u(t){console.error("[BScroll warn]: "+t)}function m(t){var i=document.createElement("div"),e=document.createElement("div");return i.style.cssText="position:absolute;z-index:9999;pointerEvents:none",e.style.cssText="box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px;",e.className="bscroll-indicator","horizontal"===t?(i.style.cssText+=";height:7px;left:2px;right:2px;bottom:0",e.style.height="100%",i.className="bscroll-horizontal-scrollbar"):(i.style.cssText+=";width:7px;bottom:2px;top:2px;right:1px",e.style.width="100%",i.className="bscroll-vertical-scrollbar"),i.style.cssText+=";overflow:hidden",i.appendChild(e),i}function f(t,i){this.wrapper=i.el,this.wrapperStyle=this.wrapper.style,this.indicator=this.wrapper.children[0],this.indicatorStyle=this.indicator.style,this.scroller=t,this.direction=i.direction,i.fade?(this.visible=0,this.wrapperStyle.opacity="0"):this.visible=1}function g(t,i){this.wrapper="string"==typeof t?document.querySelector(t):t,this.wrapper||u("can not resolve the wrapper dom"),this.scroller=this.wrapper.children[0],this.scroller||u("the wrapper need at least one child element to be scroller"),this.scrollerStyle=this.scroller.style,this._init(t,i)}var v=function(){function t(t,i){var e=[],s=!0,o=!1,n=void 0;try{for(var r,h=t[Symbol.iterator]();!(s=(r=h.next()).done)&&(e.push(r.value),!i||e.length!==i);s=!0);}catch(t){o=!0,n=t}finally{try{!s&&h.return&&h.return()}finally{if(o)throw n}}return e}return function(i,e){if(Array.isArray(i))return i;if(Symbol.iterator in Object(i))return t(i,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),y=function(t){if(Array.isArray(t)){for(var i=0,e=Array(t.length);ithis.maxPosY){this.transitionTime(500);var e=Math.max(this.indicatorHeight-3*(t-this.maxPosY),8);this.indicatorStyle.height=e+"px",t=this.maxPosY+this.indicatorHeight-e}else this.indicatorStyle.height=this.indicatorHeight+"px";this.y=t,this.scroller.options.useTransform?this.indicatorStyle[X.transform]="translateY("+t+"px)"+this.scroller.translateZ:this.indicatorStyle.top=t+"px"}else{var s=Math.round(this.sizeRatioX*this.scroller.x);if(s<0){this.transitionTime(500);var o=Math.max(this.indicatorWidth+3*s,8);this.indicatorStyle.width=o+"px",s=0}else if(s>this.maxPosX){this.transitionTime(500);var n=Math.max(this.indicatorWidth-3*(s-this.maxPosX),8);this.indicatorStyle.width=n+"px",s=this.maxPosX+this.indicatorWidth-n}else this.indicatorStyle.width=this.indicatorWidth+"px";this.x=s,this.scroller.options.useTransform?this.indicatorStyle[X.transform]="translateX("+s+"px)"+this.scroller.translateZ:this.indicatorStyle.left=s+"px"}},f.prototype.transitionTime=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.indicatorStyle[X.transitionDuration]=t+"ms"},f.prototype.transitionTimingFunction=function(t){this.indicatorStyle[X.transitionTimingFunction]=t},f.prototype.remove=function(){this.wrapper.parentNode.removeChild(this.wrapper)},f.prototype._calculate=function(){if("vertical"===this.direction){var t=this.wrapper.clientHeight;this.indicatorHeight=Math.max(Math.round(t*t/(this.scroller.scrollerHeight||t||1)),8),this.indicatorStyle.height=this.indicatorHeight+"px",this.maxPosY=t-this.indicatorHeight,this.sizeRatioY=this.maxPosY/this.scroller.maxScrollY}else{var i=this.wrapper.clientWidth;this.indicatorWidth=Math.max(Math.round(i*i/(this.scroller.scrollerWidth||i||1)),8),this.indicatorStyle.width=this.indicatorWidth+"px",this.maxPosX=i-this.indicatorWidth,this.sizeRatioX=this.maxPosX/this.scroller.maxScrollX}},function(t){t.prototype._init=function(t,i){this._handleOptions(i),this._events={},this.x=0,this.y=0,this.directionX=0,this.directionY=0,this._addDOMEvents(),this._initExtFeatures(),this._watchTransition(),this.refresh(),this.options.snap||this.scrollTo(this.options.startX,this.options.startY),this.enable()},t.prototype._handleOptions=function(t){this.options=p({},E,t),this.translateZ=this.options.HWCompositing&&b?" translateZ(0)":"",this.options.useTransition=this.options.useTransition&&Y,this.options.useTransform=this.options.useTransform&&P,this.options.preventDefault=!this.options.eventPassthrough&&this.options.preventDefault,this.options.scrollX="horizontal"!==this.options.eventPassthrough&&this.options.scrollX,this.options.scrollY="vertical"!==this.options.eventPassthrough&&this.options.scrollY,this.options.freeScroll=this.options.freeScroll&&!this.options.eventPassthrough,this.options.directionLockThreshold=this.options.eventPassthrough?0:this.options.directionLockThreshold,!0===this.options.tap&&(this.options.tap="tap")},t.prototype._addDOMEvents=function(){var t=i;this._handleDOMEvents(t)},t.prototype._removeDOMEvents=function(){var t=e;this._handleDOMEvents(t)},t.prototype._handleDOMEvents=function(t){var i=this.options.bindToWrapper?this.wrapper:window;t(window,"orientationchange",this),t(window,"resize",this),this.options.click&&t(this.wrapper,"click",this,!0),this.options.disableMouse||(t(this.wrapper,"mousedown",this),t(i,"mousemove",this),t(i,"mousecancel",this),t(i,"mouseup",this)),S&&!this.options.disableTouch&&(t(this.wrapper,"touchstart",this),t(i,"touchmove",this),t(i,"touchcancel",this),t(i,"touchend",this)),t(this.scroller,X.transitionEnd,this)},t.prototype._initExtFeatures=function(){this.options.snap&&this._initSnap(),this.options.scrollbar&&this._initScrollbar(),this.options.pullUpLoad&&this._initPullUp(),this.options.pullDownRefresh&&this._initPullDown(),this.options.wheel&&this._initWheel()},t.prototype.handleEvent=function(t){switch(t.type){case"touchstart":case"mousedown":this._start(t);break;case"touchmove":case"mousemove":this._move(t);break;case"touchend":case"mouseup":case"touchcancel":case"mousecancel":this._end(t);break;case"orientationchange":case"resize":this._resize();break;case"transitionend":case"webkitTransitionEnd":case"oTransitionEnd":case"MSTransitionEnd":this._transitionEnd(t);break;case"click":this.enabled&&!t._constructed&&(n(t.target,this.options.preventDefaultException)||t.preventDefault(),t.stopPropagation())}},t.prototype.refresh=function(){var t=o(this.wrapper);this.wrapperWidth=t.width,this.wrapperHeight=t.height;var i=o(this.scroller);this.scrollerWidth=i.width,this.scrollerHeight=i.height;var e=this.options.wheel;e?(this.items=this.scroller.children,this.options.itemHeight=this.itemHeight=this.items.length?this.scrollerHeight/this.items.length:0,void 0===this.selectedIndex&&(this.selectedIndex=e.selectedIndex||0),this.options.startY=-this.selectedIndex*this.itemHeight,this.maxScrollX=0,this.maxScrollY=-this.itemHeight*(this.items.length-1)):(this.maxScrollX=this.wrapperWidth-this.scrollerWidth,this.maxScrollY=this.wrapperHeight-this.scrollerHeight),this.hasHorizontalScroll=this.options.scrollX&&this.maxScrollX<0,this.hasVerticalScroll=this.options.scrollY&&this.maxScrollY<0,this.hasHorizontalScroll||(this.maxScrollX=0,this.scrollerWidth=this.wrapperWidth),this.hasVerticalScroll||(this.maxScrollY=0,this.scrollerHeight=this.wrapperHeight),this.endTime=0,this.directionX=0,this.directionY=0,this.wrapperOffset=s(this.wrapper),this.trigger("refresh"),this.resetPosition()},t.prototype.enable=function(){this.enabled=!0},t.prototype.disable=function(){this.enabled=!1},t.prototype._watchTransition=function(){var t=!1,i=this,e=this.scroller.style.pointerEvents||"auto";Object.defineProperty(this,"isInTransition",{get:function(){return t},set:function(s){t=s,i.scroller.style.pointerEvents=t?"none":e}})}}(g),function(t){t.prototype._start=function(t){var i=M[t.type];if((i===_||0===t.button)&&!(!this.enabled||this.destroyed||this.initiated&&this.initiated!==i)){this.initiated=i,this.options.preventDefault&&!n(t.target,this.options.preventDefaultException)&&t.preventDefault(),this.moved=!1,this.distX=0,this.distY=0,this.directionX=0,this.directionY=0,this.movingDirectionX=0,this.movingDirectionY=0,this.directionLocked=0,this._transitionTime(),this.startTime=c(),this.options.wheel&&(this.target=t.target),this.stop();var e=t.touches?t.touches[0]:t;this.startX=this.x,this.startY=this.y,this.absStartX=this.x,this.absStartY=this.y,this.pointX=e.pageX,this.pointY=e.pageY,this.trigger("beforeScrollStart")}},t.prototype._move=function(t){if(this.enabled&&!this.destroyed&&M[t.type]===this.initiated){this.options.preventDefault&&t.preventDefault();var i=t.touches?t.touches[0]:t,e=i.pageX-this.pointX,s=i.pageY-this.pointY;this.pointX=i.pageX,this.pointY=i.pageY,this.distX+=e,this.distY+=s;var o=Math.abs(this.distX),n=Math.abs(this.distY),r=c();if(!(r-this.endTime>this.options.momentumLimitTime&&nn+this.options.directionLockThreshold?this.directionLocked="h":n>=o+this.options.directionLockThreshold?this.directionLocked="v":this.directionLocked="n"),"h"===this.directionLocked){if("vertical"===this.options.eventPassthrough)t.preventDefault();else if("horizontal"===this.options.eventPassthrough)return void(this.initiated=!1);s=0}else if("v"===this.directionLocked){if("horizontal"===this.options.eventPassthrough)t.preventDefault();else if("vertical"===this.options.eventPassthrough)return void(this.initiated=!1);e=0}e=this.hasHorizontalScroll?e:0,s=this.hasVerticalScroll?s:0,this.movingDirectionX=e>0?-1:e<0?1:0,this.movingDirectionY=s>0?-1:s<0?1:0;var h=this.x+e,a=this.y+s;(h>0||h0?0:this.maxScrollX),(a>0||a0?0:this.maxScrollY),this.moved||(this.moved=!0,this.trigger("scrollStart")),this._translate(h,a),r-this.startTime>this.options.momentumLimitTime&&(this.startTime=r,this.startX=this.x,this.startY=this.y,1===this.options.probeType&&this.trigger("scroll",{x:this.x,y:this.y})),this.options.probeType>1&&this.trigger("scroll",{x:this.x,y:this.y});var l=document.documentElement.scrollLeft||window.pageXOffset||document.body.scrollLeft,p=document.documentElement.scrollTop||window.pageYOffset||document.body.scrollTop,d=this.pointX-l,u=this.pointY-p;(d>document.documentElement.clientWidth-this.options.momentumLimitDistance||ddocument.documentElement.clientHeight-this.options.momentumLimitDistance)&&this._end(t)}}},t.prototype._end=function(t){if(this.enabled&&!this.destroyed&&M[t.type]===this.initiated){this.initiated=!1,this.options.preventDefault&&!n(t.target,this.options.preventDefaultException)&&t.preventDefault(),this.trigger("touchEnd",{x:this.x,y:this.y});var i=this.stopFromTransition;if(this.stopFromTransition=!1,!(this.options.pullDownRefresh&&this._checkPullDown()||this.resetPosition(this.options.bounceTime,D.bounce))){this.isInTransition=!1;var e=Math.round(this.x),o=Math.round(this.y);if(this.moved){this.scrollTo(e,o);var a=e-this.absStartX,l=o-this.absStartY;this.directionX=a>0?-1:a<0?1:0,this.directionY=l>0?-1:l<0?1:0,this.endTime=c();var p=this.endTime-this.startTime,u=Math.abs(e-this.startX),m=Math.abs(o-this.startY);if(this._events.flick&&pthis.options.momentumLimitDistance||u>this.options.momentumLimitDistance)){var g=this.hasHorizontalScroll?d(this.x,this.startX,p,this.maxScrollX,this.options.bounce?this.wrapperWidth:0,this.options):{destination:e,duration:0},v=this.hasVerticalScroll?d(this.y,this.startY,p,this.maxScrollY,this.options.bounce?this.wrapperHeight:0,this.options):{destination:o,duration:0};e=g.destination,o=v.destination,f=Math.max(g.duration,v.duration),this.isInTransition=!0}else this.options.wheel&&(o=Math.round(o/this.itemHeight)*this.itemHeight,f=this.options.wheel.adjustTime||400);var y=D.swipe;if(this.options.snap){var w=this._nearestSnap(e,o);this.currentPage=w,f=this.options.snapSpeed||Math.max(Math.max(Math.min(Math.abs(e-w.x),1e3),Math.min(Math.abs(o-w.y),1e3)),300),e=w.x,o=w.y,this.directionX=0,this.directionY=0,y=D.bounce}if(e!==this.x||o!==this.y)return(e>0||e0||o0&&void 0!==arguments[0]?arguments[0]:"transform";this.scrollerStyle[X.transitionProperty]=t},t.prototype._transitionTime=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(this.scrollerStyle[X.transitionDuration]=t+"ms",this.options.wheel)for(var i=0;i=l)return n.isAnimating=!1,n._translate(t,i),void(n.pulling||n.resetPosition(n.options.bounceTime)||n.trigger("scrollEnd",{x:n.x,y:n.y}));var d=s(p=(p-a)/e),u=(t-r)*d+r,m=(i-h)*d+h;n._translate(u,m),n.isAnimating&&(n.animateTimer=H(o)),3===n.options.probeType&&n.trigger("scroll",{x:n.x,y:n.y})}var n=this,r=this.x,h=this.y,a=c(),l=a+e;this.isAnimating=!0,k(this.animateTimer),o()},t.prototype.scrollBy=function(t,i){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D.bounce;t=this.x+t,i=this.y+i,this.scrollTo(t,i,e,s)},t.prototype.scrollTo=function(t,i){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D.bounce;this.isInTransition=this.options.useTransition&&e>0&&(t!==this.x||i!==this.y),!e||this.options.useTransition?(this._transitionProperty(),this._transitionTimingFunction(s.style),this._transitionTime(e),this._translate(t,i),e&&3===this.options.probeType&&this._startProbe(),this.options.wheel&&(i>0?this.selectedIndex=0:i0?0:r.left0?0:r.top0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:D.bounce,e=this.x;!this.hasHorizontalScroll||e>0?e=0:e0?s=0:s2&&void 0!==arguments[2]?arguments[2]:this;this._events[t]||(this._events[t]=[]),this._events[t].push([i,e])},t.prototype.once=function(t,i){function e(){this.off(t,e),o||(o=!0,i.apply(s,arguments))}var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this,o=!1;e.fn=i,this.on(t,e)},t.prototype.off=function(t,i){var e=this._events[t];if(e)for(var s=e.length;s--;)(e[s][0]===i||e[s][0]&&e[s][0].fn===i)&&(e[s][0]=void 0)},t.prototype.trigger=function(t){var i=this._events[t];if(i)for(var e=i.length,s=[].concat(y(i)),o=0;o0&&(a(e[e.length-1].cloneNode(!0),this.scroller),this.scroller.appendChild(e[1].cloneNode(!0)))}var s=i.el;"string"==typeof s&&(s=this.scroller.querySelectorAll(s)),this.on("refresh",function(){if(t.pages=[],t.wrapperWidth&&t.wrapperHeight&&t.scrollerWidth&&t.scrollerHeight){var e=i.stepX||t.wrapperWidth,n=i.stepY||t.wrapperHeight,r=0,h=void 0,a=void 0,l=void 0,c=0,p=void 0,d=0,u=void 0,m=void 0;if(s)for(p=s.length,u=-1;ct.maxScrollX&&d++;else for(a=Math.round(e/2),l=Math.round(n/2);r>-t.scrollerWidth;){for(t.pages[c]=[],p=0,h=0;h>-t.scrollerHeight;)t.pages[c][p]={x:Math.max(r,t.maxScrollX),y:Math.max(h,t.maxScrollY),width:e,height:n,cx:r-a,cy:h-l},h-=n,p++;r-=e,c++}var f=i.loop?1:0;t.goToPage(t.currentPage.pageX||f,t.currentPage.pageY||0,0);var g=i.threshold;g%1==0?(t.snapThresholdX=g,t.snapThresholdY=g):(t.snapThresholdX=Math.round(t.pages[t.currentPage.pageX][t.currentPage.pageY].width*g),t.snapThresholdY=Math.round(t.pages[t.currentPage.pageX][t.currentPage.pageY].height*g))}}),this.on("scrollEnd",function(){i.loop&&(0===t.currentPage.pageX&&t.goToPage(t.pages.length-2,t.currentPage.pageY,0),t.currentPage.pageX===t.pages.length-1&&t.goToPage(1,t.currentPage.pageY,0))}),!1!==i.listenFlick&&this.on("flick",function(){var e=i.speed||Math.max(Math.max(Math.min(Math.abs(t.x-t.startX),1e3),Math.min(Math.abs(t.y-t.startY),1e3)),300);t.goToPage(t.currentPage.pageX+t.directionX,t.currentPage.pageY+t.directionY,e)})},t.prototype._nearestSnap=function(t,i){if(!this.pages.length)return{x:0,y:0,pageX:0,pageY:0};var e=0;if(Math.abs(t-this.absStartX)<=this.snapThresholdX&&Math.abs(i-this.absStartY)<=this.snapThresholdY)return this.currentPage;t>0?t=0:t0?i=0:i=this.pages[e][0].cx){t=this.pages[e][0].x;break}s=this.pages[e].length;for(var o=0;o=this.pages[0][o].cy){i=this.pages[0][o].y;break}return e===this.currentPage.pageX&&((e+=this.directionX)<0?e=0:e>=this.pages.length&&(e=this.pages.length-1),t=this.pages[e][0].x),o===this.currentPage.pageY&&((o+=this.directionY)<0?o=0:o>=this.pages[0].length&&(o=this.pages[0].length-1),i=this.pages[0][o].y),{x:t,y:i,pageX:e,pageY:o}},t.prototype.goToPage=function(t,i,e){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D.bounce,o=this.options.snap;t>=this.pages.length?t=this.pages.length-1:t<0&&(t=0),i>=this.pages[t].length?i=this.pages[t].length-1:i<0&&(i=0);var n=this.pages[t][i].x,r=this.pages[t][i].y;e=void 0===e?o.speed||Math.max(Math.max(Math.min(Math.abs(n-this.x),1e3),Math.min(Math.abs(r-this.y),1e3)),300):e,this.currentPage={x:n,y:r,pageX:t,pageY:i},this.scrollTo(n,r,e,s)},t.prototype.next=function(t,i){var e=this.currentPage.pageX,s=this.currentPage.pageY;++e>=this.pages.length&&this.hasVerticalScroll&&(e=0,s++),this.goToPage(e,s,t,i)},t.prototype.prev=function(t,i){var e=this.currentPage.pageX,s=this.currentPage.pageY;--e<0&&this.hasVerticalScroll&&(e=0,s--),this.goToPage(e,s,t,i)},t.prototype.getCurrentPage=function(){return this.options.snap&&this.currentPage}}(g),function(t){t.prototype.wheelTo=function(t){this.options.wheel&&(this.y=-t*this.itemHeight,this.scrollTo(0,this.y))},t.prototype.getSelectedIndex=function(){return this.options.wheel&&this.selectedIndex},t.prototype._initWheel=function(){var t=this.options.wheel;t.wheelWrapperClass||(t.wheelWrapperClass="wheel-scroll"),t.wheelItemClass||(t.wheelItemClass="wheel-item"),void 0===t.selectedIndex&&(t.selectedIndex=0,u("wheel option selectedIndex is required!"))}}(g),function(t){t.prototype._initScrollbar=function(){var t=this,i=this.options.scrollbar.fade,e=void 0===i||i;this.indicators=[];var s=void 0;this.options.scrollX&&(s={el:m("horizontal"),direction:"horizontal",fade:e},this._insertScrollBar(s.el),this.indicators.push(new f(this,s))),this.options.scrollY&&(s={el:m("vertical"),direction:"vertical",fade:e},this._insertScrollBar(s.el),this.indicators.push(new f(this,s))),this.on("refresh",function(){for(var i=0;ie&&(this.pulling||(this.pulling=!0,this.trigger("pullingDown")),this.scrollTo(this.x,o,this.options.bounceTime,D.bounce)),this.pulling},t.prototype.finishPullDown=function(){this.pulling=!1,this.resetPosition(this.options.bounceTime,D.bounce)}}(g),function(t){t.prototype._initPullUp=function(){this.options.probeType=3,this.pullupWatching=!1,this._watchPullUp()},t.prototype._watchPullUp=function(){function t(i){1===this.movingDirectionY&&i.y<=this.maxScrollY+e&&(this.trigger("pullingUp"),this.pullupWatching=!1,this.off("scroll",t))}if(!this.pullupWatching){this.pullupWatching=!0;var i=this.options.pullUpLoad.threshold,e=void 0===i?0:i;this.on("scroll",t)}},t.prototype.finishPullUp=function(){var t=this;this.isInTransition?this.once("scrollEnd",function(){t._watchPullUp()}):this._watchPullUp()}}(g),g.Version="1.4.2",g}); \ No newline at end of file