aboutsummaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-10-29 13:30:11 +0000
committerGitHub <noreply@github.com>2017-10-29 13:30:11 +0000
commit43dfa066c7841f7cb899c80c1dca44fe763bf17d (patch)
treefc580e601396783d3efbf9f5bdc83e8ac7eb753a /src/content
parent8314bcba628668c0e1fbbcb7f59f97dd4f070037 (diff)
parent9c277d0b0463e75ad771ecdf444c7c8aeee65bed (diff)
Merge pull request #110 from ueokande/107-scroll-window-and-body
scroll html and body preferentially
Diffstat (limited to 'src/content')
-rw-r--r--src/content/scrolls.js20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/content/scrolls.js b/src/content/scrolls.js
index a975296..d88320f 100644
--- a/src/content/scrolls.js
+++ b/src/content/scrolls.js
@@ -20,13 +20,13 @@ const isVisible = (win, element) => {
return true;
};
-const isScrollable = (win, element) => {
+const isScrollableStyle = (win, element) => {
let { overflowX, overflowY } = win.getComputedStyle(element);
- if (element.tagName !== 'HTML' &&
- overflowX !== 'scroll' && overflowX !== 'auto' &&
- overflowY !== 'scroll' && overflowY !== 'auto') {
- return false;
- }
+ return !(overflowX !== 'scroll' && overflowX !== 'auto' &&
+ overflowY !== 'scroll' && overflowY !== 'auto');
+};
+
+const isOverflowed = (element) => {
return element.scrollWidth > element.clientWidth ||
element.scrollHeight > element.clientHeight;
};
@@ -36,7 +36,7 @@ const isScrollable = (win, element) => {
// method is not cached. That does not cause performance issue because in the
// most pages, the window is root element i,e, documentElement.
const findScrollable = (win, element) => {
- if (isScrollable(win, element)) {
+ if (isScrollableStyle(win, element) && isOverflowed(element)) {
return element;
}
@@ -52,6 +52,12 @@ const findScrollable = (win, element) => {
};
const scrollTarget = (win) => {
+ if (isOverflowed(win.document.documentElement)) {
+ return win.document.documentElement;
+ }
+ if (isOverflowed(win.document.body)) {
+ return win.document.body;
+ }
let target = findScrollable(win, win.document.documentElement);
if (target) {
return target;