fix popperjs get scrollParent bug (#1143)

pull/1207/head
baiyaaaaa 2016-11-17 21:47:10 +08:00 committed by Leopoldthecoder
parent fc41cf4077
commit c9ff94e267
1 changed files with 12 additions and 6 deletions

View File

@ -1042,7 +1042,13 @@
* @returns {Element} offset parent * @returns {Element} offset parent
*/ */
function getScrollParent(element) { function getScrollParent(element) {
if (element === root.document) { var parent = element.parentNode;
if (!parent) {
return element;
}
if (parent === root.document) {
// Firefox puts the scrollTOp value on `documentElement` instead of `body`, we then check which of them is // Firefox puts the scrollTOp value on `documentElement` instead of `body`, we then check which of them is
// greater than 0 and return the proper element // greater than 0 and return the proper element
if (root.document.body.scrollTop) { if (root.document.body.scrollTop) {
@ -1054,16 +1060,16 @@
// Firefox want us to check `-x` and `-y` variations as well // Firefox want us to check `-x` and `-y` variations as well
if ( if (
['scroll', 'auto'].indexOf(getStyleComputedProperty(element, 'overflow')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow')) !== -1 ||
['scroll', 'auto'].indexOf(getStyleComputedProperty(element, 'overflow-x')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-x')) !== -1 ||
['scroll', 'auto'].indexOf(getStyleComputedProperty(element, 'overflow-y')) !== -1 ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-y')) !== -1
) { ) {
// If the detected scrollParent is body, we perform an additional check on its parentNode // If the detected scrollParent is body, we perform an additional check on its parentNode
// in this way we'll get body if the browser is Chrome-ish, or documentElement otherwise // in this way we'll get body if the browser is Chrome-ish, or documentElement otherwise
// fixes issue #65 // fixes issue #65
return element === root.document.body ? getScrollParent(element.parentNode) : element; return parent;
} }
return element.parentNode ? getScrollParent(element.parentNode) : element; return getScrollParent(element.parentNode);
} }
/** /**