aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-10-29 22:20:41 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-10-29 22:21:18 +0900
commit9c277d0b0463e75ad771ecdf444c7c8aeee65bed (patch)
treefc580e601396783d3efbf9f5bdc83e8ac7eb753a
parent8314bcba628668c0e1fbbcb7f59f97dd4f070037 (diff)
scroll html and body preferentially
-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;