Commit 4f563e6e authored by HJ's avatar HJ 🐼

account for parent padding, too

parent daa0e284
Pipeline #17583 failed with stages
in 1 minute
...@@ -4,17 +4,27 @@ export const findOffset = (child, parent, { top = 0, left = 0 } = {}, ignorePadd ...@@ -4,17 +4,27 @@ export const findOffset = (child, parent, { top = 0, left = 0 } = {}, ignorePadd
left: left + child.offsetLeft left: left + child.offsetLeft
} }
if (!ignorePadding && child !== window) { if (!ignorePadding && child !== window) {
const topPaddingStr = window.getComputedStyle(child)['padding-top'] const { topPadding, leftPadding } = findPadding(child)
const topPadding = Number(topPaddingStr.substring(0, topPaddingStr.length - 2))
const leftPaddingStr = window.getComputedStyle(child)['padding-left']
const leftPadding = Number(leftPaddingStr.substring(0, leftPaddingStr.length - 2))
result.top += ignorePadding ? 0 : topPadding result.top += ignorePadding ? 0 : topPadding
result.left += ignorePadding ? 0 : leftPadding result.left += ignorePadding ? 0 : leftPadding
} }
if (child.offsetParent && (parent === window || parent.contains(child.offsetParent))) { console.log('eee', parent, child.offsetParent)
if (child.offsetParent && (parent === window || parent.contains(child.offsetParent) || parent === child.offsetParent)) {
return findOffset(child.offsetParent, parent, result, false) return findOffset(child.offsetParent, parent, result, false)
} else { } else {
const { topPadding, leftPadding } = findPadding(parent)
result.top += topPadding
result.left += leftPadding
return result return result
} }
} }
const findPadding = (el) => {
const topPaddingStr = window.getComputedStyle(el)['padding-top']
const topPadding = Number(topPaddingStr.substring(0, topPaddingStr.length - 2))
const leftPaddingStr = window.getComputedStyle(el)['padding-left']
const leftPadding = Number(leftPaddingStr.substring(0, leftPaddingStr.length - 2))
return { topPadding, leftPadding }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment