Skip to content

Commit dd25def

Browse files
author
Ola Holmström
committed
Merge branch 'patch-2' of https://github.com/tremby/scrollparent.js into tremby-patch-2
2 parents eb147b2 + 1334f95 commit dd25def

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ npm install scrollparent --save
1313
```js
1414
var Scrollparent = require("scrollparent");
1515

16-
Scrollparent(document.getElementById("content")) // document.body
16+
Scrollparent(document.getElementById("content")) // HTMLHtmlElement or HTMLBodyElement as appropriate
1717
```
1818

1919
```js
@@ -22,6 +22,20 @@ var Scrollparent = require("scrollparent");
2222
Scrollparent(document.getElementById("inside-a-scrolling-div")) // HTMLDivElement
2323
```
2424

25+
## Note about the root scrolling element
26+
27+
Internally, the root scrolling element is determined in this library
28+
as the result of
29+
30+
```js
31+
document.scrollingElement || document.htmlElement
32+
```
33+
34+
This should give a usable result in most browsers today
35+
but if you want to ensure full support
36+
you should use a `document.scrollingElement` polyfill such as
37+
[this one](https://github.com/mathiasbynens/document.scrollingElement).
38+
2539
## Contributors
2640

2741
* Ola Holmström (@olahol)

scrollparent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
}
4141
}
4242

43-
return document.body;
43+
return document.scrollingElement || document.documentElement;
4444
};
4545

4646
return scrollParent;

test.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@
127127

128128
equal(Scrollparent(document.getElementById("test1")).className, "scroll");
129129

130-
equal(Scrollparent(document.getElementById("test2")), document.body);
131-
equal(Scrollparent(document.getElementById("test3")), document.body);
130+
equal(Scrollparent(document.getElementById("test2")), document.scrollingElement || document.documentElement);
131+
equal(Scrollparent(document.getElementById("test3")), document.scrollingElement || document.documentElement);
132132

133133
equal(Scrollparent(document.getElementById("test4")).className, "scroll-y");
134134
equal(Scrollparent(document.getElementById("test5")).className, "scroll-x");

0 commit comments

Comments
 (0)