From cb93e58402e15a3b51d58784d71fc0f27438592e Mon Sep 17 00:00:00 2001 From: Fanus Date: Tue, 5 Apr 2016 11:25:32 +0200 Subject: [PATCH 1/2] Can now target different scroller Added an optional parameter to iScroll in order to target a different scroller element instead of always using the first child element --- build/iscroll.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build/iscroll.js b/build/iscroll.js index 6ab9256c..cf1817df 100644 --- a/build/iscroll.js +++ b/build/iscroll.js @@ -270,10 +270,9 @@ var utils = (function () { return me; })(); -function IScroll (el, options) { +function IScroll (el, options, scroller) { this.wrapper = typeof el == 'string' ? document.querySelector(el) : el; - this.scroller = this.wrapper.children[0]; - this.scrollerStyle = this.scroller.style; // cache style for better performance + this.options = { @@ -305,6 +304,9 @@ function IScroll (el, options) { useTransform: true, bindToWrapper: typeof window.onmousedown === "undefined" }; + + this.scroller = (typeof scroller == 'undefined') ? this.wrapper.children[0] : scroller; + this.scrollerStyle = this.scroller.style; // cache style for better performance for ( var i in options ) { this.options[i] = options[i]; From 5d10f83275f0bb7129a1ed19dd3ea53b6d5d815d Mon Sep 17 00:00:00 2001 From: Fanus Date: Tue, 5 Apr 2016 12:45:59 +0200 Subject: [PATCH 2/2] Added snapWait option and fixed snapping bug Added: snapWait option that when set to true, you can only goToPage to the next section if the previous snap animation/transition finised. Fixed: When snap is set to true and you mouseWheelScroll up at the first page or mouseWheelScroll down at the last page, you cannot scroll anymore. Should also improve performance of goToPage function in general. --- build/iscroll.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build/iscroll.js b/build/iscroll.js index cf1817df..1e6d9a1f 100644 --- a/build/iscroll.js +++ b/build/iscroll.js @@ -302,7 +302,9 @@ function IScroll (el, options, scroller) { HWCompositing: true, useTransition: true, useTransform: true, - bindToWrapper: typeof window.onmousedown === "undefined" + bindToWrapper: typeof window.onmousedown === "undefined", + + snapWait: false }; this.scroller = (typeof scroller == 'undefined') ? this.wrapper.children[0] : scroller; @@ -1354,6 +1356,9 @@ IScroll.prototype = { }, goToPage: function (x, y, time, easing) { + if(this.options.snapWait && ((!this.options.useTransition && this.isAnimating) || (this.options.useTransition && this.isInTransition))) + return; + easing = easing || this.options.bounceEasing; if ( x >= this.pages.length ) { @@ -1364,8 +1369,10 @@ IScroll.prototype = { if ( y >= this.pages[x].length ) { y = this.pages[x].length - 1; + return; } else if ( y < 0 ) { y = 0; + return; } var posX = this.pages[x][y].x,