iscroll-20140819-min.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. ! function(window, document, Math) {
  2. function IScroll(el, options) {
  3. this.wrapper = "string" == typeof el ? document.querySelector(el) : el, this.scroller = this.wrapper.children[0], this.scrollerStyle = this.scroller.style, this.options = {
  4. resizeScrollbars: !0,
  5. mouseWheelSpeed: 20,
  6. snapThreshold: .334,
  7. startX: 0,
  8. startY: 0,
  9. scrollY: !0,
  10. directionLockThreshold: 5,
  11. momentum: !0,
  12. bounce: !0,
  13. bounceTime: 600,
  14. bounceEasing: "",
  15. preventDefault: !0,
  16. preventDefaultException: {
  17. tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/
  18. },
  19. HWCompositing: !0,
  20. useTransition: !0,
  21. useTransform: !0
  22. };
  23. for (var i in options) this.options[i] = options[i];
  24. this.translateZ = this.options.HWCompositing && utils.hasPerspective ? " translateZ(0)" : "", this.options.useTransition = utils.hasTransition && this.options.useTransition, this.options.useTransform = utils.hasTransform && this.options.useTransform, this.options.eventPassthrough = this.options.eventPassthrough === !0 ? "vertical" : this.options.eventPassthrough, this.options.preventDefault = !this.options.eventPassthrough && this.options.preventDefault, this.options.scrollY = "vertical" == this.options.eventPassthrough ? !1 : this.options.scrollY, this.options.scrollX = "horizontal" == this.options.eventPassthrough ? !1 : this.options.scrollX, this.options.freeScroll = this.options.freeScroll && !this.options.eventPassthrough, this.options.directionLockThreshold = this.options.eventPassthrough ? 0 : this.options.directionLockThreshold, this.options.bounceEasing = "string" == typeof this.options.bounceEasing ? utils.ease[this.options.bounceEasing] || utils.ease.circular : this.options.bounceEasing, this.options.resizePolling = void 0 === this.options.resizePolling ? 60 : this.options.resizePolling, this.options.tap === !0 && (this.options.tap = "tap"), "scale" == this.options.shrinkScrollbars && (this.options.useTransition = !1), this.options.invertWheelDirection = this.options.invertWheelDirection ? -1 : 1, this.x = 0, this.y = 0, this.directionX = 0, this.directionY = 0, this._events = {}, this._init(), this.refresh(), this.scrollTo(this.options.startX, this.options.startY), this.enable()
  25. }
  26. function createDefaultScrollbar(direction, interactive, type) {
  27. var scrollbar = document.createElement("div"),
  28. indicator = document.createElement("div");
  29. return type === !0 && (scrollbar.style.cssText = "position:absolute;z-index:9999", indicator.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;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 = "iScrollIndicator", "h" == direction ? (type === !0 && (scrollbar.style.cssText += ";height:7px;left:2px;right:2px;bottom:0", indicator.style.height = "100%"), scrollbar.className = "iScrollHorizontalScrollbar") : (type === !0 && (scrollbar.style.cssText += ";width:7px;bottom:2px;top:2px;right:1px", indicator.style.width = "100%"), scrollbar.className = "iScrollVerticalScrollbar"), scrollbar.style.cssText += ";overflow:hidden", interactive || (scrollbar.style.pointerEvents = "none"), scrollbar.appendChild(indicator), scrollbar
  30. }
  31. function Indicator(scroller, options) {
  32. this.wrapper = "string" == typeof options.el ? document.querySelector(options.el) : options.el, this.wrapperStyle = this.wrapper.style, this.indicator = this.wrapper.children[0], this.indicatorStyle = this.indicator.style, this.scroller = scroller, this.options = {
  33. listenX: !0,
  34. listenY: !0,
  35. interactive: !1,
  36. resize: !0,
  37. defaultScrollbars: !1,
  38. shrink: !1,
  39. fade: !1,
  40. speedRatioX: 0,
  41. speedRatioY: 0
  42. };
  43. for (var i in options) this.options[i] = options[i];
  44. this.sizeRatioX = 1, this.sizeRatioY = 1, this.maxPosX = 0, this.maxPosY = 0, this.options.interactive && (this.options.disableTouch || (utils.addEvent(this.indicator, "touchstart", this), utils.addEvent(window, "touchend", this)), this.options.disablePointer || (utils.addEvent(this.indicator, utils.prefixPointerEvent("pointerdown"), this), utils.addEvent(window, utils.prefixPointerEvent("pointerup"), this)), this.options.disableMouse || (utils.addEvent(this.indicator, "mousedown", this), utils.addEvent(window, "mouseup", this))), this.options.fade && (this.wrapperStyle[utils.style.transform] = this.scroller.translateZ, this.wrapperStyle[utils.style.transitionDuration] = utils.isBadAndroid ? "0.001s" : "0ms", this.wrapperStyle.opacity = "0")
  45. }
  46. var rAF = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {
  47. window.setTimeout(callback, 1e3 / 60)
  48. },
  49. utils = function() {
  50. function _prefixStyle(style) {
  51. return _vendor === !1 ? !1 : "" === _vendor ? style : _vendor + style.charAt(0).toUpperCase() + style.substr(1)
  52. }
  53. var me = {},
  54. _elementStyle = document.createElement("div").style,
  55. _vendor = function() {
  56. for (var transform, vendors = ["t", "webkitT", "MozT", "msT", "OT"], i = 0, l = vendors.length; l > i; i++)
  57. if (transform = vendors[i] + "ransform", transform in _elementStyle) return vendors[i].substr(0, vendors[i].length - 1);
  58. return !1
  59. }();
  60. me.getTime = Date.now || function() {
  61. return (new Date).getTime()
  62. }, me.extend = function(target, obj) {
  63. for (var i in obj) target[i] = obj[i]
  64. }, me.addEvent = function(el, type, fn, capture) {
  65. el.addEventListener(type, fn, !!capture)
  66. }, me.removeEvent = function(el, type, fn, capture) {
  67. el.removeEventListener(type, fn, !!capture)
  68. }, me.prefixPointerEvent = function(pointerEvent) {
  69. return window.MSPointerEvent ? "MSPointer" + pointerEvent.charAt(9).toUpperCase() + pointerEvent.substr(10) : pointerEvent
  70. }, me.momentum = function(current, start, time, lowerMargin, wrapperSize, deceleration) {
  71. var destination, duration, distance = current - start,
  72. speed = Math.abs(distance) / time;
  73. return deceleration = void 0 === deceleration ? 6e-4 : deceleration, destination = current + speed * speed / (2 * deceleration) * (0 > distance ? -1 : 1), duration = speed / deceleration, lowerMargin > destination ? (destination = wrapperSize ? lowerMargin - wrapperSize / 2.5 * (speed / 8) : lowerMargin, distance = Math.abs(destination - current), duration = distance / speed) : destination > 0 && (destination = wrapperSize ? wrapperSize / 2.5 * (speed / 8) : 0, distance = Math.abs(current) + destination, duration = distance / speed), {
  74. destination: Math.round(destination),
  75. duration: duration
  76. }
  77. };
  78. var _transform = _prefixStyle("transform");
  79. return me.extend(me, {
  80. hasTransform: _transform !== !1,
  81. hasPerspective: _prefixStyle("perspective") in _elementStyle,
  82. hasTouch: "ontouchstart" in window,
  83. hasPointer: window.PointerEvent || window.MSPointerEvent,
  84. hasTransition: _prefixStyle("transition") in _elementStyle
  85. }), me.isBadAndroid = /Android /.test(window.navigator.appVersion) && !/Chrome\/\d/.test(window.navigator.appVersion), me.extend(me.style = {}, {
  86. transform: _transform,
  87. transitionTimingFunction: _prefixStyle("transitionTimingFunction"),
  88. transitionDuration: _prefixStyle("transitionDuration"),
  89. transitionDelay: _prefixStyle("transitionDelay"),
  90. transformOrigin: _prefixStyle("transformOrigin")
  91. }), me.hasClass = function(e, c) {
  92. var re = new RegExp("(^|\\s)" + c + "(\\s|$)");
  93. return re.test(e.className)
  94. }, me.addClass = function(e, c) {
  95. if (!me.hasClass(e, c)) {
  96. var newclass = e.className.split(" ");
  97. newclass.push(c), e.className = newclass.join(" ")
  98. }
  99. }, me.removeClass = function(e, c) {
  100. if (me.hasClass(e, c)) {
  101. var re = new RegExp("(^|\\s)" + c + "(\\s|$)", "g");
  102. e.className = e.className.replace(re, " ")
  103. }
  104. }, me.offset = function(el) {
  105. for (var left = -el.offsetLeft, top = -el.offsetTop; el = el.offsetParent;) left -= el.offsetLeft, top -= el.offsetTop;
  106. return {
  107. left: left,
  108. top: top
  109. }
  110. }, me.preventDefaultException = function(el, exceptions) {
  111. for (var i in exceptions)
  112. if (exceptions[i].test(el[i])) return !0;
  113. return !1
  114. }, me.extend(me.eventType = {}, {
  115. touchstart: 1,
  116. touchmove: 1,
  117. touchend: 1,
  118. mousedown: 2,
  119. mousemove: 2,
  120. mouseup: 2,
  121. pointerdown: 3,
  122. pointermove: 3,
  123. pointerup: 3,
  124. MSPointerDown: 3,
  125. MSPointerMove: 3,
  126. MSPointerUp: 3
  127. }), me.extend(me.ease = {}, {
  128. quadratic: {
  129. style: "cubic-bezier(0.25, 0.46, 0.45, 0.94)",
  130. fn: function(k) {
  131. return k * (2 - k)
  132. }
  133. },
  134. circular: {
  135. style: "cubic-bezier(0.1, 0.57, 0.1, 1)",
  136. fn: function(k) {
  137. return Math.sqrt(1 - --k * k)
  138. }
  139. },
  140. back: {
  141. style: "cubic-bezier(0.175, 0.885, 0.32, 1.275)",
  142. fn: function(k) {
  143. var b = 4;
  144. return (k -= 1) * k * ((b + 1) * k + b) + 1
  145. }
  146. },
  147. bounce: {
  148. style: "",
  149. fn: function(k) {
  150. return (k /= 1) < 1 / 2.75 ? 7.5625 * k * k : 2 / 2.75 > k ? 7.5625 * (k -= 1.5 / 2.75) * k + .75 : 2.5 / 2.75 > k ? 7.5625 * (k -= 2.25 / 2.75) * k + .9375 : 7.5625 * (k -= 2.625 / 2.75) * k + .984375
  151. }
  152. },
  153. elastic: {
  154. style: "",
  155. fn: function(k) {
  156. var f = .22,
  157. e = .4;
  158. return 0 === k ? 0 : 1 == k ? 1 : e * Math.pow(2, -10 * k) * Math.sin(2 * (k - f / 4) * Math.PI / f) + 1
  159. }
  160. }
  161. }), me.tap = function(e, eventName) {
  162. var ev = document.createEvent("Event");
  163. ev.initEvent(eventName, !0, !0), ev.pageX = e.pageX, ev.pageY = e.pageY, e.target.dispatchEvent(ev)
  164. }, me.click = function(e) {
  165. var ev, target = e.target;
  166. /(SELECT|INPUT|TEXTAREA)/i.test(target.tagName) || (ev = document.createEvent("MouseEvents"), ev.initMouseEvent("click", !0, !0, e.view, 1, target.screenX, target.screenY, target.clientX, target.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 0, null), ev._constructed = !0, target.dispatchEvent(ev))
  167. }, me
  168. }();
  169. IScroll.prototype = {
  170. version: "5.1.2",
  171. _init: function() {
  172. this._initEvents(), (this.options.scrollbars || this.options.indicators) && this._initIndicators(), this.options.mouseWheel && this._initWheel(), this.options.snap && this._initSnap(), this.options.keyBindings && this._initKeys()
  173. },
  174. destroy: function() {
  175. this._initEvents(!0), this._execEvent("destroy")
  176. },
  177. _transitionEnd: function(e) {
  178. e.target == this.scroller && this.isInTransition && (this._transitionTime(), this.resetPosition(this.options.bounceTime) || (this.isInTransition = !1, this._execEvent("scrollEnd")))
  179. },
  180. _start: function(e) {
  181. if (!(1 != utils.eventType[e.type] && 0 !== e.button || !this.enabled || this.initiated && utils.eventType[e.type] !== this.initiated)) {
  182. !this.options.preventDefault || utils.isBadAndroid || utils.preventDefaultException(e.target, this.options.preventDefaultException) || e.preventDefault();
  183. var pos, point = e.touches ? e.touches[0] : e;
  184. this.initiated = utils.eventType[e.type], this.moved = !1, this.distX = 0, this.distY = 0, this.directionX = 0, this.directionY = 0, this.directionLocked = 0, this._transitionTime(), this.startTime = utils.getTime(), this.options.useTransition && this.isInTransition ? (this.isInTransition = !1, pos = this.getComputedPosition(), this._translate(Math.round(pos.x), Math.round(pos.y)), this._execEvent("scrollEnd")) : !this.options.useTransition && this.isAnimating && (this.isAnimating = !1, this._execEvent("scrollEnd")), 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._execEvent("beforeScrollStart")
  185. }
  186. },
  187. _move: function(e) {
  188. if (this.enabled && utils.eventType[e.type] === this.initiated) {
  189. this.options.preventDefault && e.preventDefault();
  190. var newX, newY, absDistX, absDistY, point = e.touches ? e.touches[0] : e,
  191. deltaX = point.pageX - this.pointX,
  192. deltaY = point.pageY - this.pointY,
  193. timestamp = utils.getTime();
  194. if (this.pointX = point.pageX, this.pointY = point.pageY, this.distX += deltaX, this.distY += deltaY, absDistX = Math.abs(this.distX), absDistY = Math.abs(this.distY), !(timestamp - this.endTime > 300 && 10 > absDistX && 10 > absDistY)) {
  195. if (this.directionLocked || this.options.freeScroll || (this.directionLocked = absDistX > absDistY + this.options.directionLockThreshold ? "h" : absDistY >= absDistX + this.options.directionLockThreshold ? "v" : "n"), "h" == this.directionLocked) {
  196. if ("vertical" == this.options.eventPassthrough) e.preventDefault();
  197. else if ("horizontal" == this.options.eventPassthrough) return void(this.initiated = !1);
  198. deltaY = 0
  199. } else if ("v" == this.directionLocked) {
  200. if ("horizontal" == this.options.eventPassthrough) e.preventDefault();
  201. else if ("vertical" == this.options.eventPassthrough) return void(this.initiated = !1);
  202. deltaX = 0
  203. }
  204. deltaX = this.hasHorizontalScroll ? deltaX : 0, deltaY = this.hasVerticalScroll ? deltaY : 0, newX = this.x + deltaX, newY = this.y + deltaY, (newX > 0 || newX < this.maxScrollX) && (newX = this.options.bounce ? this.x + deltaX / 3 : newX > 0 ? 0 : this.maxScrollX), (newY > 0 || newY < this.maxScrollY) && (newY = this.options.bounce ? this.y + deltaY / 3 : newY > 0 ? 0 : this.maxScrollY), this.directionX = deltaX > 0 ? -1 : 0 > deltaX ? 1 : 0, this.directionY = deltaY > 0 ? -1 : 0 > deltaY ? 1 : 0, this.moved || this._execEvent("scrollStart"), this.moved = !0, this._translate(newX, newY), timestamp - this.startTime > 300 && (this.startTime = timestamp, this.startX = this.x, this.startY = this.y)
  205. }
  206. }
  207. },
  208. _end: function(e) {
  209. if (this.enabled && utils.eventType[e.type] === this.initiated) {
  210. this.options.preventDefault && !utils.preventDefaultException(e.target, this.options.preventDefaultException) && e.preventDefault();
  211. var momentumX, momentumY, duration = (e.changedTouches ? e.changedTouches[0] : e, utils.getTime() - this.startTime),
  212. newX = Math.round(this.x),
  213. newY = Math.round(this.y),
  214. distanceX = Math.abs(newX - this.startX),
  215. distanceY = Math.abs(newY - this.startY),
  216. time = 0,
  217. easing = "";
  218. if (this.isInTransition = 0, this.initiated = 0, this.endTime = utils.getTime(), !this.resetPosition(this.options.bounceTime)) {
  219. if (this.scrollTo(newX, newY), !this.moved) return this.options.tap && utils.tap(e, this.options.tap), this.options.click && utils.click(e), void this._execEvent("scrollCancel");
  220. if (this._events.flick && 200 > duration && 100 > distanceX && 100 > distanceY) return void this._execEvent("flick");
  221. if (this.options.momentum && 300 > duration && (momentumX = this.hasHorizontalScroll ? utils.momentum(this.x, this.startX, duration, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options.deceleration) : {
  222. destination: newX,
  223. duration: 0
  224. }, momentumY = this.hasVerticalScroll ? utils.momentum(this.y, this.startY, duration, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options.deceleration) : {
  225. destination: newY,
  226. duration: 0
  227. }, newX = momentumX.destination, newY = momentumY.destination, time = Math.max(momentumX.duration, momentumY.duration), this.isInTransition = 1), this.options.snap) {
  228. var snap = this._nearestSnap(newX, newY);
  229. this.currentPage = snap, time = this.options.snapSpeed || Math.max(Math.max(Math.min(Math.abs(newX - snap.x), 1e3), Math.min(Math.abs(newY - snap.y), 1e3)), 300), newX = snap.x, newY = snap.y, this.directionX = 0, this.directionY = 0, easing = this.options.bounceEasing
  230. }
  231. return newX != this.x || newY != this.y ? ((newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY) && (easing = utils.ease.quadratic), void this.scrollTo(newX, newY, time, easing)) : void this._execEvent("scrollEnd")
  232. }
  233. }
  234. },
  235. _resize: function() {
  236. var that = this;
  237. clearTimeout(this.resizeTimeout), this.resizeTimeout = setTimeout(function() {
  238. that.refresh()
  239. }, this.options.resizePolling)
  240. },
  241. resetPosition: function(time) {
  242. var x = this.x,
  243. y = this.y;
  244. return time = time || 0, !this.hasHorizontalScroll || this.x > 0 ? x = 0 : this.x < this.maxScrollX && (x = this.maxScrollX), !this.hasVerticalScroll || this.y > 0 ? y = 0 : this.y < this.maxScrollY && (y = this.maxScrollY), x == this.x && y == this.y ? !1 : (this.scrollTo(x, y, time, this.options.bounceEasing), !0)
  245. },
  246. disable: function() {
  247. this.enabled = !1
  248. },
  249. enable: function() {
  250. this.enabled = !0
  251. },
  252. refresh: function() {
  253. this.wrapper.offsetHeight;
  254. this.wrapperWidth = this.wrapper.clientWidth, this.wrapperHeight = this.wrapper.clientHeight, this.scrollerWidth = this.scroller.offsetWidth, this.scrollerHeight = this.scroller.offsetHeight, 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 = utils.offset(this.wrapper), this._execEvent("refresh"), this.resetPosition()
  255. },
  256. on: function(type, fn) {
  257. this._events[type] || (this._events[type] = []), this._events[type].push(fn)
  258. },
  259. off: function(type, fn) {
  260. if (this._events[type]) {
  261. var index = this._events[type].indexOf(fn);
  262. index > -1 && this._events[type].splice(index, 1)
  263. }
  264. },
  265. _execEvent: function(type) {
  266. if (this._events[type]) {
  267. var i = 0,
  268. l = this._events[type].length;
  269. if (l)
  270. for (; l > i; i++) this._events[type][i].apply(this, [].slice.call(arguments, 1))
  271. }
  272. },
  273. scrollBy: function(x, y, time, easing) {
  274. x = this.x + x, y = this.y + y, time = time || 0, this.scrollTo(x, y, time, easing)
  275. },
  276. scrollTo: function(x, y, time, easing) {
  277. easing = easing || utils.ease.circular, this.isInTransition = this.options.useTransition && time > 0, !time || this.options.useTransition && easing.style ? (this._transitionTimingFunction(easing.style), this._transitionTime(time), this._translate(x, y)) : this._animate(x, y, time, easing.fn)
  278. },
  279. scrollToElement: function(el, time, offsetX, offsetY, easing) {
  280. if (el = el.nodeType ? el : this.scroller.querySelector(el)) {
  281. var pos = utils.offset(el);
  282. pos.left -= this.wrapperOffset.left, pos.top -= this.wrapperOffset.top, offsetX === !0 && (offsetX = Math.round(el.offsetWidth / 2 - this.wrapper.offsetWidth / 2)), offsetY === !0 && (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, time = void 0 === time || null === time || "auto" === time ? Math.max(Math.abs(this.x - pos.left), Math.abs(this.y - pos.top)) : time, this.scrollTo(pos.left, pos.top, time, easing)
  283. }
  284. },
  285. _transitionTime: function(time) {
  286. if (time = time || 0, this.scrollerStyle[utils.style.transitionDuration] = time + "ms", !time && utils.isBadAndroid && (this.scrollerStyle[utils.style.transitionDuration] = "0.001s"), this.indicators)
  287. for (var i = this.indicators.length; i--;) this.indicators[i].transitionTime(time)
  288. },
  289. _transitionTimingFunction: function(easing) {
  290. if (this.scrollerStyle[utils.style.transitionTimingFunction] = easing, this.indicators)
  291. for (var i = this.indicators.length; i--;) this.indicators[i].transitionTimingFunction(easing)
  292. },
  293. _translate: function(x, y) {
  294. if (this.options.useTransform ? this.scrollerStyle[utils.style.transform] = "translate(" + x + "px," + y + "px)" + this.translateZ : (x = Math.round(x), y = Math.round(y), this.scrollerStyle.left = x + "px", this.scrollerStyle.top = y + "px"), this.x = x, this.y = y, this.indicators)
  295. for (var i = this.indicators.length; i--;) this.indicators[i].updatePosition()
  296. },
  297. _initEvents: function(remove) {
  298. var eventType = remove ? utils.removeEvent : utils.addEvent,
  299. target = this.options.bindToWrapper ? this.wrapper : window;
  300. eventType(window, "orientationchange", this), eventType(window, "resize", this), this.options.click && eventType(this.wrapper, "click", this, !0), this.options.disableMouse || (eventType(this.wrapper, "mousedown", this), eventType(target, "mousemove", this), eventType(target, "mousecancel", this), eventType(target, "mouseup", this)), utils.hasPointer && !this.options.disablePointer && (eventType(this.wrapper, utils.prefixPointerEvent("pointerdown"), this), eventType(target, utils.prefixPointerEvent("pointermove"), this), eventType(target, utils.prefixPointerEvent("pointercancel"), this), eventType(target, utils.prefixPointerEvent("pointerup"), this)), utils.hasTouch && !this.options.disableTouch && (eventType(this.wrapper, "touchstart", this), eventType(target, "touchmove", this), eventType(target, "touchcancel", this), eventType(target, "touchend", this)), eventType(this.scroller, "transitionend", this), eventType(this.scroller, "webkitTransitionEnd", this), eventType(this.scroller, "oTransitionEnd", this), eventType(this.scroller, "MSTransitionEnd", this)
  301. },
  302. getComputedPosition: function() {
  303. var x, y, matrix = window.getComputedStyle(this.scroller, null);
  304. return this.options.useTransform ? (matrix = matrix[utils.style.transform].split(")")[0].split(", "), x = +(matrix[12] || matrix[4]), y = +(matrix[13] || matrix[5])) : (x = +matrix.left.replace(/[^-\d.]/g, ""), y = +matrix.top.replace(/[^-\d.]/g, "")), {
  305. x: x,
  306. y: y
  307. }
  308. },
  309. _initIndicators: function() {
  310. function _indicatorsMap(fn) {
  311. for (var i = that.indicators.length; i--;) fn.call(that.indicators[i])
  312. }
  313. var indicator, interactive = this.options.interactiveScrollbars,
  314. customStyle = "string" != typeof this.options.scrollbars,
  315. indicators = [],
  316. that = this;
  317. this.indicators = [], this.options.scrollbars && (this.options.scrollY && (indicator = {
  318. el: createDefaultScrollbar("v", interactive, this.options.scrollbars),
  319. interactive: interactive,
  320. defaultScrollbars: !0,
  321. customStyle: customStyle,
  322. resize: this.options.resizeScrollbars,
  323. shrink: this.options.shrinkScrollbars,
  324. fade: this.options.fadeScrollbars,
  325. listenX: !1
  326. }, this.wrapper.appendChild(indicator.el), indicators.push(indicator)), this.options.scrollX && (indicator = {
  327. el: createDefaultScrollbar("h", interactive, this.options.scrollbars),
  328. interactive: interactive,
  329. defaultScrollbars: !0,
  330. customStyle: customStyle,
  331. resize: this.options.resizeScrollbars,
  332. shrink: this.options.shrinkScrollbars,
  333. fade: this.options.fadeScrollbars,
  334. listenY: !1
  335. }, this.wrapper.appendChild(indicator.el), indicators.push(indicator))), this.options.indicators && (indicators = indicators.concat(this.options.indicators));
  336. for (var i = indicators.length; i--;) this.indicators.push(new Indicator(this, indicators[i]));
  337. this.options.fadeScrollbars && (this.on("scrollEnd", function() {
  338. _indicatorsMap(function() {
  339. this.fade()
  340. })
  341. }), this.on("scrollCancel", function() {
  342. _indicatorsMap(function() {
  343. this.fade()
  344. })
  345. }), this.on("scrollStart", function() {
  346. _indicatorsMap(function() {
  347. this.fade(1)
  348. })
  349. }), this.on("beforeScrollStart", function() {
  350. _indicatorsMap(function() {
  351. this.fade(1, !0)
  352. })
  353. })), this.on("refresh", function() {
  354. _indicatorsMap(function() {
  355. this.refresh()
  356. })
  357. }), this.on("destroy", function() {
  358. _indicatorsMap(function() {
  359. this.destroy()
  360. }), delete this.indicators
  361. })
  362. },
  363. _initWheel: function() {
  364. utils.addEvent(this.wrapper, "wheel", this), utils.addEvent(this.wrapper, "mousewheel", this), utils.addEvent(this.wrapper, "DOMMouseScroll", this), this.on("destroy", function() {
  365. utils.removeEvent(this.wrapper, "wheel", this), utils.removeEvent(this.wrapper, "mousewheel", this), utils.removeEvent(this.wrapper, "DOMMouseScroll", this)
  366. })
  367. },
  368. _wheel: function(e) {
  369. if (this.enabled) {
  370. e.preventDefault(), e.stopPropagation();
  371. var wheelDeltaX, wheelDeltaY, newX, newY, that = this;
  372. if (void 0 === this.wheelTimeout && that._execEvent("scrollStart"), clearTimeout(this.wheelTimeout), this.wheelTimeout = setTimeout(function() {
  373. that._execEvent("scrollEnd"), that.wheelTimeout = void 0
  374. }, 400), "deltaX" in e) wheelDeltaX = -e.deltaX, wheelDeltaY = -e.deltaY;
  375. else if ("wheelDeltaX" in e) wheelDeltaX = e.wheelDeltaX / 120 * this.options.mouseWheelSpeed, wheelDeltaY = e.wheelDeltaY / 120 * this.options.mouseWheelSpeed;
  376. else if ("wheelDelta" in e) wheelDeltaX = wheelDeltaY = e.wheelDelta / 120 * this.options.mouseWheelSpeed;
  377. else {
  378. if (!("detail" in e)) return;
  379. wheelDeltaX = wheelDeltaY = -e.detail / 3 * this.options.mouseWheelSpeed
  380. } if (wheelDeltaX *= this.options.invertWheelDirection, wheelDeltaY *= this.options.invertWheelDirection, this.hasVerticalScroll || (wheelDeltaX = wheelDeltaY, wheelDeltaY = 0), this.options.snap) return newX = this.currentPage.pageX, newY = this.currentPage.pageY, wheelDeltaX > 0 ? newX-- : 0 > wheelDeltaX && newX++, wheelDeltaY > 0 ? newY-- : 0 > wheelDeltaY && newY++, void this.goToPage(newX, newY);
  381. newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0), newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0), newX > 0 ? newX = 0 : newX < this.maxScrollX && (newX = this.maxScrollX), newY > 0 ? newY = 0 : newY < this.maxScrollY && (newY = this.maxScrollY), this.scrollTo(newX, newY, 0)
  382. }
  383. },
  384. _initSnap: function() {
  385. this.currentPage = {}, "string" == typeof this.options.snap && (this.options.snap = this.scroller.querySelectorAll(this.options.snap)), this.on("refresh", function() {
  386. var l, n, cx, cy, y, el, i = 0,
  387. m = 0,
  388. x = 0,
  389. stepX = this.options.snapStepX || this.wrapperWidth,
  390. stepY = this.options.snapStepY || this.wrapperHeight;
  391. if (this.pages = [], this.wrapperWidth && this.wrapperHeight && this.scrollerWidth && this.scrollerHeight) {
  392. if (this.options.snap === !0)
  393. for (cx = Math.round(stepX / 2), cy = Math.round(stepY / 2); x > -this.scrollerWidth;) {
  394. for (this.pages[i] = [], l = 0, y = 0; y > -this.scrollerHeight;) this.pages[i][l] = {
  395. x: Math.max(x, this.maxScrollX),
  396. y: Math.max(y, this.maxScrollY),
  397. width: stepX,
  398. height: stepY,
  399. cx: x - cx,
  400. cy: y - cy
  401. }, y -= stepY, l++;
  402. x -= stepX, i++
  403. } else
  404. for (el = this.options.snap, l = el.length, n = -1; l > i; i++)(0 === i || el[i].offsetLeft <= el[i - 1].offsetLeft) && (m = 0, n++), this.pages[m] || (this.pages[m] = []), x = Math.max(-el[i].offsetLeft, this.maxScrollX), y = Math.max(-el[i].offsetTop, this.maxScrollY), cx = x - Math.round(el[i].offsetWidth / 2), cy = y - Math.round(el[i].offsetHeight / 2), this.pages[m][n] = {
  405. x: x,
  406. y: y,
  407. width: el[i].offsetWidth,
  408. height: el[i].offsetHeight,
  409. cx: cx,
  410. cy: cy
  411. }, x > this.maxScrollX && m++;
  412. this.goToPage(this.currentPage.pageX || 0, this.currentPage.pageY || 0, 0), this.options.snapThreshold % 1 === 0 ? (this.snapThresholdX = this.options.snapThreshold, this.snapThresholdY = this.options.snapThreshold) : (this.snapThresholdX = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].width * this.options.snapThreshold), this.snapThresholdY = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].height * this.options.snapThreshold))
  413. }
  414. }), this.on("flick", function() {
  415. var time = this.options.snapSpeed || Math.max(Math.max(Math.min(Math.abs(this.x - this.startX), 1e3), Math.min(Math.abs(this.y - this.startY), 1e3)), 300);
  416. this.goToPage(this.currentPage.pageX + this.directionX, this.currentPage.pageY + this.directionY, time)
  417. })
  418. },
  419. _nearestSnap: function(x, y) {
  420. if (!this.pages.length) return {
  421. x: 0,
  422. y: 0,
  423. pageX: 0,
  424. pageY: 0
  425. };
  426. var i = 0,
  427. l = this.pages.length,
  428. m = 0;
  429. if (Math.abs(x - this.absStartX) < this.snapThresholdX && Math.abs(y - this.absStartY) < this.snapThresholdY) return this.currentPage;
  430. for (x > 0 ? x = 0 : x < this.maxScrollX && (x = this.maxScrollX), y > 0 ? y = 0 : y < this.maxScrollY && (y = this.maxScrollY); l > i; i++)
  431. if (x >= this.pages[i][0].cx) {
  432. x = this.pages[i][0].x;
  433. break
  434. }
  435. for (l = this.pages[i].length; l > m; m++)
  436. if (y >= this.pages[0][m].cy) {
  437. y = this.pages[0][m].y;
  438. break
  439. }
  440. return i == this.currentPage.pageX && (i += this.directionX, 0 > i ? i = 0 : i >= this.pages.length && (i = this.pages.length - 1), x = this.pages[i][0].x), m == this.currentPage.pageY && (m += this.directionY, 0 > m ? m = 0 : m >= this.pages[0].length && (m = this.pages[0].length - 1), y = this.pages[0][m].y), {
  441. x: x,
  442. y: y,
  443. pageX: i,
  444. pageY: m
  445. }
  446. },
  447. goToPage: function(x, y, time, easing) {
  448. easing = easing || this.options.bounceEasing, x >= this.pages.length ? x = this.pages.length - 1 : 0 > x && (x = 0), y >= this.pages[x].length ? y = this.pages[x].length - 1 : 0 > y && (y = 0);
  449. var posX = this.pages[x][y].x,
  450. posY = this.pages[x][y].y;
  451. time = void 0 === time ? this.options.snapSpeed || Math.max(Math.max(Math.min(Math.abs(posX - this.x), 1e3), Math.min(Math.abs(posY - this.y), 1e3)), 300) : time, this.currentPage = {
  452. x: posX,
  453. y: posY,
  454. pageX: x,
  455. pageY: y
  456. }, this.scrollTo(posX, posY, time, easing)
  457. },
  458. next: function(time, easing) {
  459. var x = this.currentPage.pageX,
  460. y = this.currentPage.pageY;
  461. x++, x >= this.pages.length && this.hasVerticalScroll && (x = 0, y++), this.goToPage(x, y, time, easing)
  462. },
  463. prev: function(time, easing) {
  464. var x = this.currentPage.pageX,
  465. y = this.currentPage.pageY;
  466. x--, 0 > x && this.hasVerticalScroll && (x = 0, y--), this.goToPage(x, y, time, easing)
  467. },
  468. _initKeys: function() {
  469. var i, keys = {
  470. pageUp: 33,
  471. pageDown: 34,
  472. end: 35,
  473. home: 36,
  474. left: 37,
  475. up: 38,
  476. right: 39,
  477. down: 40
  478. };
  479. if ("object" == typeof this.options.keyBindings)
  480. for (i in this.options.keyBindings) "string" == typeof this.options.keyBindings[i] && (this.options.keyBindings[i] = this.options.keyBindings[i].toUpperCase().charCodeAt(0));
  481. else this.options.keyBindings = {};
  482. for (i in keys) this.options.keyBindings[i] = this.options.keyBindings[i] || keys[i];
  483. utils.addEvent(window, "keydown", this), this.on("destroy", function() {
  484. utils.removeEvent(window, "keydown", this)
  485. })
  486. },
  487. _key: function(e) {
  488. if (this.enabled) {
  489. var pos, snap = this.options.snap,
  490. newX = snap ? this.currentPage.pageX : this.x,
  491. newY = snap ? this.currentPage.pageY : this.y,
  492. now = utils.getTime(),
  493. prevTime = this.keyTime || 0,
  494. acceleration = .25;
  495. switch (this.options.useTransition && this.isInTransition && (pos = this.getComputedPosition(), this._translate(Math.round(pos.x), Math.round(pos.y)), this.isInTransition = !1), this.keyAcceleration = 200 > now - prevTime ? Math.min(this.keyAcceleration + acceleration, 50) : 0, e.keyCode) {
  496. case this.options.keyBindings.pageUp:
  497. this.hasHorizontalScroll && !this.hasVerticalScroll ? newX += snap ? 1 : this.wrapperWidth : newY += snap ? 1 : this.wrapperHeight;
  498. break;
  499. case this.options.keyBindings.pageDown:
  500. this.hasHorizontalScroll && !this.hasVerticalScroll ? newX -= snap ? 1 : this.wrapperWidth : newY -= snap ? 1 : this.wrapperHeight;
  501. break;
  502. case this.options.keyBindings.end:
  503. newX = snap ? this.pages.length - 1 : this.maxScrollX, newY = snap ? this.pages[0].length - 1 : this.maxScrollY;
  504. break;
  505. case this.options.keyBindings.home:
  506. newX = 0, newY = 0;
  507. break;
  508. case this.options.keyBindings.left:
  509. newX += snap ? -1 : 5 + this.keyAcceleration >> 0;
  510. break;
  511. case this.options.keyBindings.up:
  512. newY += snap ? 1 : 5 + this.keyAcceleration >> 0;
  513. break;
  514. case this.options.keyBindings.right:
  515. newX -= snap ? -1 : 5 + this.keyAcceleration >> 0;
  516. break;
  517. case this.options.keyBindings.down:
  518. newY -= snap ? 1 : 5 + this.keyAcceleration >> 0;
  519. break;
  520. default:
  521. return
  522. }
  523. if (snap) return void this.goToPage(newX, newY);
  524. newX > 0 ? (newX = 0, this.keyAcceleration = 0) : newX < this.maxScrollX && (newX = this.maxScrollX, this.keyAcceleration = 0), newY > 0 ? (newY = 0, this.keyAcceleration = 0) : newY < this.maxScrollY && (newY = this.maxScrollY, this.keyAcceleration = 0), this.scrollTo(newX, newY, 0), this.keyTime = now
  525. }
  526. },
  527. _animate: function(destX, destY, duration, easingFn) {
  528. function step() {
  529. var newX, newY, easing, now = utils.getTime();
  530. return now >= destTime ? (that.isAnimating = !1, that._translate(destX, destY), void(that.resetPosition(that.options.bounceTime) || that._execEvent("scrollEnd"))) : (now = (now - startTime) / duration, easing = easingFn(now), newX = (destX - startX) * easing + startX, newY = (destY - startY) * easing + startY, that._translate(newX, newY), void(that.isAnimating && rAF(step)))
  531. }
  532. var that = this,
  533. startX = this.x,
  534. startY = this.y,
  535. startTime = utils.getTime(),
  536. destTime = startTime + duration;
  537. this.isAnimating = !0, step()
  538. },
  539. handleEvent: function(e) {
  540. switch (e.type) {
  541. case "touchstart":
  542. case "pointerdown":
  543. case "MSPointerDown":
  544. case "mousedown":
  545. this._start(e);
  546. break;
  547. case "touchmove":
  548. case "pointermove":
  549. case "MSPointerMove":
  550. case "mousemove":
  551. this._move(e);
  552. break;
  553. case "touchend":
  554. case "pointerup":
  555. case "MSPointerUp":
  556. case "mouseup":
  557. case "touchcancel":
  558. case "pointercancel":
  559. case "MSPointerCancel":
  560. case "mousecancel":
  561. this._end(e);
  562. break;
  563. case "orientationchange":
  564. case "resize":
  565. this._resize();
  566. break;
  567. case "transitionend":
  568. case "webkitTransitionEnd":
  569. case "oTransitionEnd":
  570. case "MSTransitionEnd":
  571. this._transitionEnd(e);
  572. break;
  573. case "wheel":
  574. case "DOMMouseScroll":
  575. case "mousewheel":
  576. this._wheel(e);
  577. break;
  578. case "keydown":
  579. this._key(e);
  580. break;
  581. case "click":
  582. e._constructed || (e.preventDefault(), e.stopPropagation())
  583. }
  584. }
  585. }, Indicator.prototype = {
  586. handleEvent: function(e) {
  587. switch (e.type) {
  588. case "touchstart":
  589. case "pointerdown":
  590. case "MSPointerDown":
  591. case "mousedown":
  592. this._start(e);
  593. break;
  594. case "touchmove":
  595. case "pointermove":
  596. case "MSPointerMove":
  597. case "mousemove":
  598. this._move(e);
  599. break;
  600. case "touchend":
  601. case "pointerup":
  602. case "MSPointerUp":
  603. case "mouseup":
  604. case "touchcancel":
  605. case "pointercancel":
  606. case "MSPointerCancel":
  607. case "mousecancel":
  608. this._end(e)
  609. }
  610. },
  611. destroy: function() {
  612. this.options.interactive && (utils.removeEvent(this.indicator, "touchstart", this), utils.removeEvent(this.indicator, utils.prefixPointerEvent("pointerdown"), this), utils.removeEvent(this.indicator, "mousedown", this), utils.removeEvent(window, "touchmove", this), utils.removeEvent(window, utils.prefixPointerEvent("pointermove"), this), utils.removeEvent(window, "mousemove", this), utils.removeEvent(window, "touchend", this), utils.removeEvent(window, utils.prefixPointerEvent("pointerup"), this), utils.removeEvent(window, "mouseup", this)), this.options.defaultScrollbars && this.wrapper.parentNode.removeChild(this.wrapper)
  613. },
  614. _start: function(e) {
  615. var point = e.touches ? e.touches[0] : e;
  616. e.preventDefault(), e.stopPropagation(), this.transitionTime(), this.initiated = !0, this.moved = !1, this.lastPointX = point.pageX, this.lastPointY = point.pageY, this.startTime = utils.getTime(), this.options.disableTouch || utils.addEvent(window, "touchmove", this), this.options.disablePointer || utils.addEvent(window, utils.prefixPointerEvent("pointermove"), this), this.options.disableMouse || utils.addEvent(window, "mousemove", this), this.scroller._execEvent("beforeScrollStart")
  617. },
  618. _move: function(e) {
  619. {
  620. var deltaX, deltaY, newX, newY, point = e.touches ? e.touches[0] : e;
  621. utils.getTime()
  622. }
  623. this.moved || this.scroller._execEvent("scrollStart"), this.moved = !0, deltaX = point.pageX - this.lastPointX, this.lastPointX = point.pageX, deltaY = point.pageY - this.lastPointY, this.lastPointY = point.pageY, newX = this.x + deltaX, newY = this.y + deltaY, this._pos(newX, newY), e.preventDefault(), e.stopPropagation()
  624. },
  625. _end: function(e) {
  626. if (this.initiated) {
  627. if (this.initiated = !1, e.preventDefault(), e.stopPropagation(), utils.removeEvent(window, "touchmove", this), utils.removeEvent(window, utils.prefixPointerEvent("pointermove"), this), utils.removeEvent(window, "mousemove", this), this.scroller.options.snap) {
  628. var snap = this.scroller._nearestSnap(this.scroller.x, this.scroller.y),
  629. time = this.options.snapSpeed || Math.max(Math.max(Math.min(Math.abs(this.scroller.x - snap.x), 1e3), Math.min(Math.abs(this.scroller.y - snap.y), 1e3)), 300);
  630. (this.scroller.x != snap.x || this.scroller.y != snap.y) && (this.scroller.directionX = 0, this.scroller.directionY = 0, this.scroller.currentPage = snap, this.scroller.scrollTo(snap.x, snap.y, time, this.scroller.options.bounceEasing))
  631. }
  632. this.moved && this.scroller._execEvent("scrollEnd")
  633. }
  634. },
  635. transitionTime: function(time) {
  636. time = time || 0, this.indicatorStyle[utils.style.transitionDuration] = time + "ms", !time && utils.isBadAndroid && (this.indicatorStyle[utils.style.transitionDuration] = "0.001s")
  637. },
  638. transitionTimingFunction: function(easing) {
  639. this.indicatorStyle[utils.style.transitionTimingFunction] = easing
  640. },
  641. refresh: function() {
  642. this.transitionTime(), this.indicatorStyle.display = this.options.listenX && !this.options.listenY ? this.scroller.hasHorizontalScroll ? "block" : "none" : this.options.listenY && !this.options.listenX ? this.scroller.hasVerticalScroll ? "block" : "none" : this.scroller.hasHorizontalScroll || this.scroller.hasVerticalScroll ? "block" : "none", this.scroller.hasHorizontalScroll && this.scroller.hasVerticalScroll ? (utils.addClass(this.wrapper, "iScrollBothScrollbars"), utils.removeClass(this.wrapper, "iScrollLoneScrollbar"), this.options.defaultScrollbars && this.options.customStyle && (this.options.listenX ? this.wrapper.style.right = "8px" : this.wrapper.style.bottom = "8px")) : (utils.removeClass(this.wrapper, "iScrollBothScrollbars"), utils.addClass(this.wrapper, "iScrollLoneScrollbar"), this.options.defaultScrollbars && this.options.customStyle && (this.options.listenX ? this.wrapper.style.right = "2px" : this.wrapper.style.bottom = "2px"));
  643. this.wrapper.offsetHeight;
  644. this.options.listenX && (this.wrapperWidth = this.wrapper.clientWidth, this.options.resize ? (this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8), this.indicatorStyle.width = this.indicatorWidth + "px") : this.indicatorWidth = this.indicator.clientWidth, this.maxPosX = this.wrapperWidth - this.indicatorWidth, "clip" == this.options.shrink ? (this.minBoundaryX = -this.indicatorWidth + 8, this.maxBoundaryX = this.wrapperWidth - 8) : (this.minBoundaryX = 0, this.maxBoundaryX = this.maxPosX), this.sizeRatioX = this.options.speedRatioX || this.scroller.maxScrollX && this.maxPosX / this.scroller.maxScrollX), this.options.listenY && (this.wrapperHeight = this.wrapper.clientHeight, this.options.resize ? (this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / (this.scroller.scrollerHeight || this.wrapperHeight || 1)), 8), this.indicatorStyle.height = this.indicatorHeight + "px") : this.indicatorHeight = this.indicator.clientHeight, this.maxPosY = this.wrapperHeight - this.indicatorHeight, "clip" == this.options.shrink ? (this.minBoundaryY = -this.indicatorHeight + 8, this.maxBoundaryY = this.wrapperHeight - 8) : (this.minBoundaryY = 0, this.maxBoundaryY = this.maxPosY), this.maxPosY = this.wrapperHeight - this.indicatorHeight, this.sizeRatioY = this.options.speedRatioY || this.scroller.maxScrollY && this.maxPosY / this.scroller.maxScrollY), this.updatePosition()
  645. },
  646. updatePosition: function() {
  647. var x = this.options.listenX && Math.round(this.sizeRatioX * this.scroller.x) || 0,
  648. y = this.options.listenY && Math.round(this.sizeRatioY * this.scroller.y) || 0;
  649. this.options.ignoreBoundaries || (x < this.minBoundaryX ? ("scale" == this.options.shrink && (this.width = Math.max(this.indicatorWidth + x, 8), this.indicatorStyle.width = this.width + "px"), x = this.minBoundaryX) : x > this.maxBoundaryX ? "scale" == this.options.shrink ? (this.width = Math.max(this.indicatorWidth - (x - this.maxPosX), 8), this.indicatorStyle.width = this.width + "px", x = this.maxPosX + this.indicatorWidth - this.width) : x = this.maxBoundaryX : "scale" == this.options.shrink && this.width != this.indicatorWidth && (this.width = this.indicatorWidth, this.indicatorStyle.width = this.width + "px"), y < this.minBoundaryY ? ("scale" == this.options.shrink && (this.height = Math.max(this.indicatorHeight + 3 * y, 8), this.indicatorStyle.height = this.height + "px"), y = this.minBoundaryY) : y > this.maxBoundaryY ? "scale" == this.options.shrink ? (this.height = Math.max(this.indicatorHeight - 3 * (y - this.maxPosY), 8), this.indicatorStyle.height = this.height + "px", y = this.maxPosY + this.indicatorHeight - this.height) : y = this.maxBoundaryY : "scale" == this.options.shrink && this.height != this.indicatorHeight && (this.height = this.indicatorHeight, this.indicatorStyle.height = this.height + "px")), this.x = x, this.y = y, this.scroller.options.useTransform ? this.indicatorStyle[utils.style.transform] = "translate(" + x + "px," + y + "px)" + this.scroller.translateZ : (this.indicatorStyle.left = x + "px", this.indicatorStyle.top = y + "px")
  650. },
  651. _pos: function(x, y) {
  652. 0 > x ? x = 0 : x > this.maxPosX && (x = this.maxPosX), 0 > y ? y = 0 : y > this.maxPosY && (y = this.maxPosY), x = this.options.listenX ? Math.round(x / this.sizeRatioX) : this.scroller.x, y = this.options.listenY ? Math.round(y / this.sizeRatioY) : this.scroller.y, this.scroller.scrollTo(x, y)
  653. },
  654. fade: function(val, hold) {
  655. if (!hold || this.visible) {
  656. clearTimeout(this.fadeTimeout), this.fadeTimeout = null;
  657. var time = val ? 250 : 500,
  658. delay = val ? 0 : 300;
  659. val = val ? "1" : "0", this.wrapperStyle[utils.style.transitionDuration] = time + "ms", this.fadeTimeout = setTimeout(function(val) {
  660. this.wrapperStyle.opacity = val, this.visible = +val
  661. }.bind(this, val), delay)
  662. }
  663. }
  664. }, IScroll.utils = utils, qike.lib.IScroll = IScroll
  665. }(window, document, Math);