Created
December 1, 2010 12:10
-
-
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.
This file contains 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
/** | |
* | |
* 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