revamp template
This commit is contained in:
30
src/utils/Dom.ts
Normal file
30
src/utils/Dom.ts
Normal file
@ -0,0 +1,30 @@
|
||||
const getViewPort = (): { width: number; height: number } => {
|
||||
let e: any = window;
|
||||
let a: string = 'inner';
|
||||
|
||||
if (!('innerWidth' in window)) {
|
||||
a = 'client';
|
||||
e = document.documentElement || document.body;
|
||||
}
|
||||
|
||||
return {
|
||||
width: e[a + 'Width'] as number,
|
||||
height: e[a + 'Height'] as number
|
||||
};
|
||||
};
|
||||
|
||||
const getHeight = (element: HTMLElement): number => {
|
||||
if (!element) return 0;
|
||||
|
||||
const styles = window.getComputedStyle(element);
|
||||
|
||||
const height = element.getBoundingClientRect().height; // Actual height of the element
|
||||
const marginTop = parseFloat(styles.marginTop);
|
||||
const marginBottom = parseFloat(styles.marginBottom);
|
||||
|
||||
const totalHeight = height + marginTop + marginBottom;
|
||||
|
||||
return totalHeight;
|
||||
};
|
||||
|
||||
export { getHeight, getViewPort };
|
||||
Reference in New Issue
Block a user