|
|
@ -20,13 +20,13 @@ const isVisible = (win, element) => { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const isScrollable = (win, element) => { |
|
|
|
const isScrollableStyle = (win, element) => { |
|
|
|
let { overflowX, overflowY } = win.getComputedStyle(element); |
|
|
|
let { overflowX, overflowY } = win.getComputedStyle(element); |
|
|
|
if (element.tagName !== 'HTML' && |
|
|
|
return !(overflowX !== 'scroll' && overflowX !== 'auto' && |
|
|
|
overflowX !== 'scroll' && overflowX !== 'auto' && |
|
|
|
overflowY !== 'scroll' && overflowY !== 'auto'); |
|
|
|
overflowY !== 'scroll' && overflowY !== 'auto') { |
|
|
|
}; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
const isOverflowed = (element) => { |
|
|
|
return element.scrollWidth > element.clientWidth || |
|
|
|
return element.scrollWidth > element.clientWidth || |
|
|
|
element.scrollHeight > element.clientHeight; |
|
|
|
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
|
|
|
|
// method is not cached. That does not cause performance issue because in the
|
|
|
|
// most pages, the window is root element i,e, documentElement.
|
|
|
|
// most pages, the window is root element i,e, documentElement.
|
|
|
|
const findScrollable = (win, element) => { |
|
|
|
const findScrollable = (win, element) => { |
|
|
|
if (isScrollable(win, element)) { |
|
|
|
if (isScrollableStyle(win, element) && isOverflowed(element)) { |
|
|
|
return element; |
|
|
|
return element; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -52,6 +52,12 @@ const findScrollable = (win, element) => { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const scrollTarget = (win) => { |
|
|
|
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); |
|
|
|
let target = findScrollable(win, win.document.documentElement); |
|
|
|
if (target) { |
|
|
|
if (target) { |
|
|
|
return target; |
|
|
|
return target; |
|
|
|