Last active
August 29, 2015 13:56
-
-
Save imyelo/9343047 to your computer and use it in GitHub Desktop.
pulldown and pullup for iScroll 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createPullabledScroll = function (iScroll, elem, options) { | |
var scroll, pullDownReady, pullUpReady; | |
// scope variable | |
pullDownReady = false; | |
pullUpReady = false; | |
// setup the scroll object | |
options.probeType = options.probeType || 2; | |
scroll = new iScroll(elem, options); | |
// pullDown | |
if (typeof options.pullDownOffset === 'number') { | |
scroll.on('scroll', function () { | |
if (this.y > options.pullDownOffset && !pullDownReady) { | |
pullDownReady = true; | |
this._execEvent('pullDownReady'); | |
} else if (this.y < options.pullDownOffset && pullDownReady) { | |
pullDownReady = false; | |
this._execEvent('pullDownCancel'); | |
} | |
}); | |
scroll.on('scrollEnd', function () { | |
if (pullDownReady) { | |
this._execEvent('pullDown'); | |
pullDownReady = false; | |
} | |
}); | |
} | |
if (typeof options.pullUpOffset === 'number') { | |
scroll.on('scroll', function () { | |
if (this.y < (this.maxScrollY - options.pullUpOffset) && !pullUpReady) { | |
pullUpReady = true; | |
this._execEvent('pullUpReady'); | |
} else if (this.y > (this.maxScrollY + options.pullUpOffset) && pullUpReady) { | |
pullUpReady = false; | |
this._execEvent('pullUpCancel'); | |
} | |
}); | |
scroll.on('scrollEnd', function () { | |
if (pullUpReady) { | |
this._execEvent('pullUp'); | |
pullDownReady = false; | |
} | |
}); | |
} | |
return scroll; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment