module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "./"; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 151); /******/ }) /************************************************************************/ /******/ ({ /***/ 151: /***/ (function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { if (true) { !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports, __webpack_require__(152), __webpack_require__(156)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else if (typeof exports !== "undefined") { factory(module, exports, require('../../components/slide/slide.vue'), require('../../components/slide/slide-item.vue')); } else { var mod = { exports: {} }; factory(mod, mod.exports, global.slide, global.slideItem); global.index = mod.exports; } })(this, function (module, exports, _slide, _slideItem) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _slide2 = _interopRequireDefault(_slide); var _slideItem2 = _interopRequireDefault(_slideItem); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } _slide2.default.install = function (Vue) { Vue.component(_slide2.default.name, _slide2.default); Vue.component(_slideItem2.default.name, _slideItem2.default); }; _slide2.default.Item = _slideItem2.default; exports.default = _slide2.default; module.exports = exports['default']; }); /***/ }), /***/ 152: /***/ (function(module, exports, __webpack_require__) { function injectStyle (ssrContext) { __webpack_require__(153) } var Component = __webpack_require__(4)( /* script */ __webpack_require__(154), /* template */ __webpack_require__(155), /* styles */ injectStyle, /* scopeId */ null, /* moduleIdentifier (server only) */ null ) module.exports = Component.exports /***/ }), /***/ 153: /***/ (function(module, exports) { // removed by extract-text-webpack-plugin /***/ }), /***/ 154: /***/ (function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { if (true) { !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports, __webpack_require__(52)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else if (typeof exports !== "undefined") { factory(module, exports, require('better-scroll')); } else { var mod = { exports: {} }; factory(mod, mod.exports, global.betterScroll); global.slide = mod.exports; } })(this, function (module, exports, _betterScroll) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _betterScroll2 = _interopRequireDefault(_betterScroll); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var COMPONENT_NAME = 'cube-slide'; var EVENT_CHANGE = 'change'; exports.default = { name: COMPONENT_NAME, props: { loop: { type: Boolean, default: true }, autoPlay: { type: Boolean, default: true }, interval: { type: Number, default: 4000 }, threshold: { type: Number, default: 0.3 }, speed: { type: Number, default: 400 } }, data: function data() { return { dots: 0, currentPageIndex: 0 }; }, methods: { refresh: function refresh() { this._setSlideWidth(true); this.slide.refresh(); }, _setSlideWidth: function _setSlideWidth(isResize) { this.children = this.$refs.slideGroup.children; var width = 0; var slideWidth = this.$refs.slide.clientWidth; for (var i = 0; i < this.children.length; i++) { var child = this.children[i]; child.style.width = slideWidth + 'px'; width += slideWidth; } if (this.loop && !isResize) { width += 2 * slideWidth; } this.$refs.slideGroup.style.width = width + 'px'; }, _initSlide: function _initSlide() { var _this = this; this.slide = new _betterScroll2.default(this.$refs.slide, { scrollX: true, scrollY: false, momentum: false, snap: { loop: this.loop, threshold: this.threshold, speed: this.speed }, click: true }); this.slide.on('scrollEnd', this._onScrollEnd); this.slide.on('touchend', function () { if (_this.autoPlay) { _this._play(); } }); this.slide.on('beforeScrollStart', function () { if (_this.autoPlay) { clearTimeout(_this._timer); } }); }, _onScrollEnd: function _onScrollEnd() { var pageIndex = this.slide.getCurrentPage().pageX; if (this.loop) { pageIndex -= 1; } if (this.currentPageIndex !== pageIndex) { this.currentPageIndex = pageIndex; this.$emit(EVENT_CHANGE, this.currentPageIndex); } if (this.autoPlay) { this._play(); } }, _initDots: function _initDots() { this.dots = new Array(this.children.length); }, _play: function _play() { var _this2 = this; var pageIndex = this.currentPageIndex + 1; if (this.loop) { pageIndex += 1; } clearTimeout(this._timer); this._timer = setTimeout(function () { _this2.slide.goToPage(pageIndex, 0, 400); }, this.interval); }, _deactivated: function _deactivated() { clearTimeout(this._timer); clearTimeout(this._resizeTimer); window.removeEventListener('resize', this._resizeHandler); }, _resizeHandler: function _resizeHandler() { var _this3 = this; if (!this.slide) { return; } clearTimeout(this._resizeTimer); this._resizeTimer = setTimeout(function () { if (_this3.slide.isInTransition) { _this3._onScrollEnd(); } else { if (_this3.autoPlay) { _this3._play(); } } _this3.refresh(); }, 60); } }, mounted: function mounted() { var _this4 = this; setTimeout(function () { _this4._setSlideWidth(); _this4._initDots(); _this4._initSlide(); if (_this4.autoPlay) { _this4._play(); } }, 20); window.addEventListener('resize', this._resizeHandler); }, activated: function activated() { if (this.autoPlay) { this._play(); } window.addEventListener('resize', this._resizeHandler); }, deactivated: function deactivated() { this._deactivated(); }, destroyed: function destroyed() { this._deactivated(); this.slide.destroy(); this.slide = null; } }; module.exports = exports['default']; }); /***/ }), /***/ 155: /***/ (function(module, exports) { module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h; return _c('div', { ref: "slide", staticClass: "cube-slide" }, [_c('div', { ref: "slideGroup", staticClass: "cube-slide-group" }, [_vm._t("default")], 2), _vm._v(" "), _c('div', { staticClass: "cube-slide-dots" }, _vm._l((_vm.dots), function(item, index) { return _c('span', { class: { active: _vm.currentPageIndex === index } }) }))]) },staticRenderFns: []} /***/ }), /***/ 156: /***/ (function(module, exports, __webpack_require__) { function injectStyle (ssrContext) { __webpack_require__(157) } var Component = __webpack_require__(4)( /* script */ __webpack_require__(158), /* template */ __webpack_require__(159), /* styles */ injectStyle, /* scopeId */ null, /* moduleIdentifier (server only) */ null ) module.exports = Component.exports /***/ }), /***/ 157: /***/ (function(module, exports) { // removed by extract-text-webpack-plugin /***/ }), /***/ 158: /***/ (function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { if (true) { !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else if (typeof exports !== "undefined") { factory(module, exports); } else { var mod = { exports: {} }; factory(mod, mod.exports); global.slideItem = mod.exports; } })(this, function (module, exports) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var COMPONENT_NAME = 'cube-slide-item'; exports.default = { name: COMPONENT_NAME }; module.exports = exports['default']; }); /***/ }), /***/ 159: /***/ (function(module, exports) { module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h; return _c('div', { staticClass: "cube-slide-item" }, [_vm._t("default")], 2) },staticRenderFns: []} /***/ }), /***/ 4: /***/ (function(module, exports) { /* globals __VUE_SSR_CONTEXT__ */ // this module is a runtime utility for cleaner component module output and will // be included in the final webpack user bundle module.exports = function normalizeComponent ( rawScriptExports, compiledTemplate, injectStyles, scopeId, moduleIdentifier /* server only */ ) { var esModule var scriptExports = rawScriptExports = rawScriptExports || {} // ES6 modules interop var type = typeof rawScriptExports.default if (type === 'object' || type === 'function') { esModule = rawScriptExports scriptExports = rawScriptExports.default } // Vue.extend constructor export interop var options = typeof scriptExports === 'function' ? scriptExports.options : scriptExports // render functions if (compiledTemplate) { options.render = compiledTemplate.render options.staticRenderFns = compiledTemplate.staticRenderFns } // scopedId if (scopeId) { options._scopeId = scopeId } var hook if (moduleIdentifier) { // server build hook = function (context) { // 2.3 injection context = context || // cached call (this.$vnode && this.$vnode.ssrContext) || // stateful (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional // 2.2 with runInNewContext: true if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') { context = __VUE_SSR_CONTEXT__ } // inject component styles if (injectStyles) { injectStyles.call(this, context) } // register component module identifier for async chunk inferrence if (context && context._registeredComponents) { context._registeredComponents.add(moduleIdentifier) } } // used by ssr in case component is cached and beforeCreate // never gets called options._ssrRegister = hook } else if (injectStyles) { hook = injectStyles } if (hook) { var functional = options.functional var existing = functional ? options.render : options.beforeCreate if (!functional) { // inject component registration as beforeCreate hook options.beforeCreate = existing ? [].concat(existing, hook) : [hook] } else { // register for functioal component in vue file options.render = function renderWithStyleInjection (h, context) { hook.call(context) return existing(h, context) } } } return { esModule: esModule, exports: scriptExports, options: options } } /***/ }), /***/ 52: /***/ (function(module, exports, __webpack_require__) { /*! * better-normal-scroll v1.4.1 * (c) 2016-2017 ustbhuangyi * Released under the MIT License. */ (function (global, factory) { true ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.BScroll = factory()); }(this, (function () { 'use strict'; 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 * } */ 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(); } }; 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; } 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 === 'wheel-scroll') { 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.abs(this.y / this.itemHeight) | 0; } 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: this.x, y: this.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.abs(y / this.itemHeight) | 0; } } } 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 !== 'wheel-item') { 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 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; }; } 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 warn(msg) { console.error("[BScroll warn]: " + msg); } 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.1'; return BScroll; }))); /***/ }) /******/ });