From 9c277d0b0463e75ad771ecdf444c7c8aeee65bed Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 29 Oct 2017 22:20:41 +0900 Subject: scroll html and body preferentially --- src/content/scrolls.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/content') 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; -- cgit v1.2.3