Skip to content

Commit 0987f08

Browse files
committed
Make plugin work in Firefox when CSS has html {scroll-behavior: smooth;}
1 parent a7cadd3 commit 0987f08

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/jquery.smooth-scroll.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,21 @@
7070
}
7171
});
7272

73-
// If no scrollable elements, fall back to <body>,
74-
// if it's in the jQuery collection
75-
// (doing this because Safari sets scrollTop async,
76-
// so can't set it to 1 and immediately get the value.)
7773
if (!scrollable.length) {
7874
this.each(function() {
79-
if (this.nodeName === 'BODY') {
75+
// If no scrollable elements and <html> has scroll-behavior:smooth because
76+
// "When this property is specified on the root element, it applies to the viewport instead."
77+
// and "The scroll-behavior property of the … body element is *not* propagated to the viewport."
78+
// → https://drafts.csswg.org/cssom-view/#propdef-scroll-behavior
79+
if (this === document.documentElement && $(this).css('scrollBehavior') === 'smooth') {
80+
scrollable = [this];
81+
}
82+
83+
// If still no scrollable elements, fall back to <body>,
84+
// if it's in the jQuery collection
85+
// (doing this because Safari sets scrollTop async,
86+
// so can't set it to 1 and immediately get the value.)
87+
if (!scrollable.length && this.nodeName === 'BODY') {
8088
scrollable = [this];
8189
}
8290
});

0 commit comments

Comments
 (0)