diff --git a/README.markdown b/README.markdown index e60f055..c589797 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,14 @@ jQuery .scrollintoview() plugin (with :scrollable selector filter) == + +This is a fork of the original jquery-scrollintoview plugin by @litera. +We forked it in order to add some extra functionality. There is a [PR pending](https://github.com/litera/jquery-scrollintoview/pull/16); +if it will get merged, we can kill this fork. + +Everyting below this line comes from the original (upstream) README file. + + * * * + This plugin makes it easy to scroll any element on your page into view. It scrolls in a user friendly way using animation (speed can be configured) so users never loose track where they moved within the current page. Default browser functionality simply jumps to some element which may confuse users greatly. This kind of behaviour is considered bad user experience, since pages look different above and below the fold. This means that users may as well think they were redirected to a different site (since it looks different) or at least page within the same site. How to use this plugin @@ -48,4 +57,4 @@ var scrollableDivs = $("div:scrollable"); This code would select all `DIV` elements that have scroll bars (at least one) and their content exceeds their visible area (at least in direction that can be scrolled using scroll bar). -[See blog post for details](http://erraticdev.blogspot.com/2011/02/jquery-scroll-into-view-plugin-with.html). \ No newline at end of file +[See blog post for details](http://erraticdev.blogspot.com/2011/02/jquery-scroll-into-view-plugin-with.html). 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); } }