Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.