summaryrefslogtreecommitdiffstats
path: root/jquery-scrollspy.js
diff options
context:
space:
mode:
authorSam Alexander <sxalexander@gmail.com>2011-10-18 23:36:59 -0700
committerSam Alexander <sxalexander@gmail.com>2011-10-18 23:36:59 -0700
commit180f5793cd1f823052126b5180cb93579f930baa (patch)
tree1bc23ff6341f89cf234cb06cda475c9a80848cd0 /jquery-scrollspy.js
parentb0537c1ad65cb6f270506c88baf800e1ff193e68 (diff)
downloadjquery-scrollspy-180f5793cd1f823052126b5180cb93579f930baa.zip
jquery-scrollspy-180f5793cd1f823052126b5180cb93579f930baa.tar.gz
jquery-scrollspy-180f5793cd1f823052126b5180cb93579f930baa.tar.bz2
Closes #1. Allows for callables as min/max
Diffstat (limited to 'jquery-scrollspy.js')
-rw-r--r--jquery-scrollspy.js27
1 files changed, 19 insertions, 8 deletions
diff --git a/jquery-scrollspy.js b/jquery-scrollspy.js
index 8f0a733..71b4a36 100644
--- a/jquery-scrollspy.js
+++ b/jquery-scrollspy.js
@@ -31,18 +31,29 @@
var mode = o.mode;
var buffer = o.buffer;
var enters = leaves = 0;
- var max = parseInt(o.max);
var inside = false;
-
- /* fix max */
- if(max == 0){
- max = (mode == 'vertical') ? $container.height() : $container.width();
- }
-
+
/* add listener to container */
$container.bind('scroll', function(e){
var position = {top: $(this).scrollTop(), left: $(this).scrollLeft()};
var xy = (mode == 'vertical') ? position.top + buffer : position.left + buffer;
+ var max = o.max;
+ var min = o.min;
+
+ /* fix max */
+ if($.isFunction(o.max)){
+ max = o.max();
+ }
+
+ /* fix max */
+ if($.isFunction(o.min)){
+ min = o.min();
+ }
+
+ if(max == 0){
+ max = (mode == 'vertical') ? $container.height() : $container.outerWidth() + $(element).outerWidth();
+ }
+
/* if we have reached the minimum bound but are below the max ... */
if(xy >= o.min && xy <= max){
/* trigger enter event */
@@ -84,4 +95,4 @@
})
-})( jQuery, window ); \ No newline at end of file
+})( jQuery, window );