Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Offset" support #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions jquery.scrollintoview.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*!
* jQuery scrollintoview() plugin and :scrollable selector filter
*
* Version 1.8 (14 Jul 2011)
* Version 1.8.a (5 May 2012)
* Requires jQuery 1.4 or newer
*
* Copyright (c) 2011 Robert Koritnik
* Licensed under the terms of the MIT license
* http://www.opensource.org/licenses/mit-license.php
*
* Modified by Alex King to add vertical offset support.
*/

(function ($) {
Expand All @@ -20,7 +22,8 @@

var settings = {
duration: "fast",
direction: "both"
direction: "both",
offset: 0
};

var rootrx = /^(?:html)$/i;
Expand Down Expand Up @@ -112,13 +115,13 @@
// vertical scroll
if (options.direction.y === true)
{
if (rel.top < 0)
if (rel.top < 0 + options.offset)
{
animOptions.scrollTop = dim.s.scroll.top + rel.top;
animOptions.scrollTop = dim.s.scroll.top + rel.top - options.offset;
}
else if (rel.top > 0 && rel.bottom < 0)
else if (rel.top > 0 + options.offset && rel.bottom < 0 - options.offset)
{
animOptions.scrollTop = dim.s.scroll.top + Math.min(rel.top, -rel.bottom);
animOptions.scrollTop = dim.s.scroll.top + Math.min(rel.top, -rel.bottom + options.offset);
}
}

Expand Down
11 changes: 9 additions & 2 deletions jquery.scrollintoview.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.