Skip to content

Instantly share code, notes, and snippets.

@joecritch
Created December 1, 2010 12:10
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 joecritch/723404 to your computer and use it in GitHub Desktop.
Save joecritch/723404 to your computer and use it in GitHub Desktop.
Custom jQuery Tools Scrollable plugin for making sure it doesn't pass the end.
/**
*
* jQuery Tools / Scrollable **Lockable** Plugin
* @author Joe Critchley, Motionlab Marketing Ltd.
*
*/
(function($) {
var t = $.tools.scrollable;
t.lockable = {
conf: {
size: 4
}
};
// jQuery plugin implementation
$.fn.lockable = function(conf) {
var opts = $.extend({}, t.lockable.conf, conf), ret;
var undefined;
this.each(function() {
var api = $(this).data("scrollable");
if (api) { ret = api; }
var currentIndex = 1,
prevIndex,
locked = false;
api.onBeforeSeek(function(e, i) {
currentIndex = i-1;
if((api.getIndex() >= (api.getSize() - opts.size))
&& (prevIndex <= currentIndex && locked === false)) {
e.preventDefault();
locked = true;
}
else {
locked = false;
}
prevIndex = currentIndex;
});
$(api.getConf().prev).click(function(e) {
e.preventDefault();
});
$(api.getConf().next).click(function(e) {
e.preventDefault();
});
});
return opts.api ? ret : this;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment