From 50d35c9a60c7f9f485028d7bdaa3bc19f3d09d30 Mon Sep 17 00:00:00 2001 From: Oliver Leics Date: Mon, 8 Apr 2013 13:22:44 +0300 Subject: [PATCH] Adds two options: .alignWithTop and .offset --- jquery.scrollIntoView.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jquery.scrollIntoView.js b/jquery.scrollIntoView.js index 4ade417..2ef4caf 100644 --- a/jquery.scrollIntoView.js +++ b/jquery.scrollIntoView.js @@ -52,7 +52,7 @@ // it wiggles? (pEl.scrollTop != ((pEl.scrollTop += 1) == null || pEl.scrollTop) && (pEl.scrollTop -= 1) != null) || (pEl.scrollTop != ((pEl.scrollTop -= 1) == null || pEl.scrollTop) && (pEl.scrollTop += 1) != null)) { - if (elY <= pY) scrollTo(pEl, elY); // scroll up + if ((opts.alignWithTop && (elY + elH) > (pY + pH)) || elY <= pY) scrollTo(pEl, elY); // scroll up else if ((elY + elH) > (pY + pH)) scrollTo(pEl, elY + elH - pH); // scroll down else scrollTo(pEl, undefined) // no scroll return; @@ -66,9 +66,9 @@ if (scrollTo === undefined) { if ($.isFunction(opts.complete)) opts.complete.call(el); } else if (opts.smooth) { - $(el).stop().animate({ scrollTop: scrollTo }, opts); + $(el).stop().animate({ scrollTop: scrollTo + opts.offset }, opts); } else { - el.scrollTop = scrollTo; + el.scrollTop = scrollTo + opts.offset; if ($.isFunction(opts.complete)) opts.complete.call(el); } } @@ -83,7 +83,9 @@ // otherwise jQuery will default to use 'swing' complete: $.noop(), step: null, - specialEasing: {} // cannot be null in jQuery 1.8.3 + specialEasing: {}, // cannot be null in jQuery 1.8.3 + alignWithTop: false, + offset: 0 }; /* @@ -134,4 +136,4 @@ return $([]); } -})(jQuery); \ No newline at end of file +})(jQuery);