From e6de215d930c448fd5120c6943da7ceab26ae011 Mon Sep 17 00:00:00 2001 From: csillag Date: Fri, 30 Jan 2015 14:40:11 +0100 Subject: [PATCH] When calling the `complete` callback, pass some info ... about the direction we scrolled. This is something that we need to know in our app. (Passing this information is harmless; compatibility with the old API is fully retained.) --- jquery.scrollintoview.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/jquery.scrollintoview.js b/jquery.scrollintoview.js index 2f7049e..f19e843 100644 --- a/jquery.scrollintoview.js +++ b/jquery.scrollintoview.js @@ -109,29 +109,37 @@ var animOptions = {}; + var yDir = "none"; + // vertical scroll if (options.direction.y === true) { if (rel.top < 0) { animOptions.scrollTop = dim.s.scroll.top + rel.top; + yDir = "up" } else if (rel.top > 0 && rel.bottom < 0) { animOptions.scrollTop = dim.s.scroll.top + Math.min(rel.top, -rel.bottom); + yDir = "down" } } + var xDir = "none"; + // horizontal scroll if (options.direction.x === true) { if (rel.left < 0) { animOptions.scrollLeft = dim.s.scroll.left + rel.left; + xDir = "left" } else if (rel.left > 0 && rel.right < 0) { animOptions.scrollLeft = dim.s.scroll.left + Math.min(rel.left, -rel.right); + xDir = "right" } } @@ -146,14 +154,14 @@ .animate(animOptions, options.duration) .eq(0) // we want function to be called just once (ref. "html,body") .queue(function (next) { - $.isFunction(options.complete) && options.complete.call(scroller[0]); + $.isFunction(options.complete) && options.complete.call(scroller[0], xDir, yDir); next(); }); } else { // when there's nothing to scroll, just call the "complete" function - $.isFunction(options.complete) && options.complete.call(scroller[0]); + $.isFunction(options.complete) && options.complete.call(scroller[0], xDir, yDir); } }