Add initial project files
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# [←](../../Readme.md) Огляд DOM утиліт
|
||||
|
||||
### # getHeight(element: HTMLElement): number
|
||||
|
||||
Повертає повну висоту елемента в пікселях, включаючи `margin-top` та `margin-bottom`.
|
||||
|
||||
Якщо елемент не передано — повертає `0`.
|
||||
|
||||
```ts
|
||||
getHeight(document.querySelector('.my-element')); // → 124 (height + margins)
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
export function getHeight(element: HTMLElement): number {
|
||||
if (!element) return 0;
|
||||
|
||||
const styles = window.getComputedStyle(element);
|
||||
|
||||
const height = element.getBoundingClientRect().height;
|
||||
const marginTop = parseFloat(styles.marginTop);
|
||||
const marginBottom = parseFloat(styles.marginBottom);
|
||||
|
||||
const totalHeight = height + marginTop + marginBottom;
|
||||
|
||||
return totalHeight;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './getHeight';
|
||||
Reference in New Issue
Block a user