Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
jQuery .scrollintoview() plugin <sup>(with :scrollable selector filter)</sup>
==

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
Expand Down Expand Up @@ -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).
[See blog post for details](http://erraticdev.blogspot.com/2011/02/jquery-scroll-into-view-plugin-with.html).
12 changes: 10 additions & 2 deletions jquery.scrollintoview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand All @@ -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);
}
}

Expand Down