Skip to content

Commit 11668bd

Browse files
committed
Ensure scrollable element is set with proper direction
1 parent 38a975a commit 11668bd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/jquery.smooth-scroll.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,11 @@ $.smoothScroll = function(options, px) {
168168

169169
if ( opts.scrollElement ) {
170170
$scroller = opts.scrollElement;
171-
scrollerOffset = $scroller[scrollDir]();
171+
if ( !(/^(?:HTML|BODY)$/).test($scroller[0].nodeName) ) {
172+
scrollerOffset = $scroller[scrollDir]();
173+
}
172174
} else {
173-
$scroller = $('html, body').firstScrollable();
175+
$scroller = $('html, body').firstScrollable(opts.direction);
174176
}
175177

176178
// beforeScroll callback function must fire before calculating offset
@@ -218,7 +220,7 @@ $.smoothScroll.version = version;
218220
$.smoothScroll.filterPath = function(string) {
219221
return string
220222
.replace(/^\//,'')
221-
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
223+
.replace(/(?:index|default).[a-zA-Z]{3,4}$/,'')
222224
.replace(/\/$/,'');
223225
};
224226

0 commit comments

Comments
 (0)