Skip to content

Instantly share code, notes, and snippets.

@imyelo
Last active August 29, 2015 13:56
Show Gist options
  • Save imyelo/9343047 to your computer and use it in GitHub Desktop.
Save imyelo/9343047 to your computer and use it in GitHub Desktop.
pulldown and pullup for iScroll 5
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