Skip to content

Instantly share code, notes, and snippets.

@plasticmind
Created June 12, 2013 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plasticmind/5767694 to your computer and use it in GitHub Desktop.
Save plasticmind/5767694 to your computer and use it in GitHub Desktop.
Behavior for Infinite Scroll jQuery plugin: infinite scrolling doesn't begin until after a manual trigger is clicked.
/*
--------------------------------
Infinite Scroll Behavior
Simply Recipes Mobile Style
: Infinite scroll waits for a one-time manual trigger
--------------------------------
by Jesse Gardner, http://plasticmind.com
*/
$.extend($.infinitescroll.prototype,{
_setup_simplyrecipes: function infscr_setup_simplyrecipes () {
var instance = this;
var opts = this.options;
this._binding('bind');
this._numScrolls = 0; // Register a scroll counter
this.options.loading.start = function (opts) {
if(instance._numScrolls==0) { // First scroll requires manual click
$(opts.navSelector).show();
$(opts.nextSelector).bind('click', function(e) {
e.preventDefault();
$(opts.navSelector).fadeOut('fast');
opts.loading.msg.appendTo(opts.loading.selector).fadeIn('fast');
instance.beginAjax(opts);
});
} else { // Anything after that happens automatically
$(opts.navSelector).hide();
opts.loading.msg.appendTo(opts.loading.selector).show(opts.loading.speed);
instance.beginAjax(opts);
}
}
this.options.loading.finished = function() {
opts.loading.msg.fadeOut('fast');
instance._numScrolls++;
}
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment