Created
February 1, 2019 10:08
-
-
Save 1natsu172/35965df83e4ab5915489285e9845d327 to your computer and use it in GitHub Desktop.
dom elementのRectを取って計算して返すくん。paddingを含まない値も欲しくてとりあえず書いたけど、ボツになったので供養
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getElementRects = (element: HTMLElement) => { | |
const heightWithPadding = element.getBoundingClientRect().height | |
const heightWithoutPadding = () => { | |
if (!getComputedStyle) return 0 | |
const { paddingTop, paddingBottom } = getComputedStyle(element) | |
const padding = | |
parseFloat(paddingTop ? paddingTop : '0') + | |
parseFloat(paddingBottom ? paddingBottom : '0') | |
return heightWithPadding - padding | |
} | |
return { | |
heightWithPadding, | |
heightWithoutPadding: heightWithoutPadding() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment