-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout.js
More file actions
35 lines (28 loc) · 946 Bytes
/
layout.js
File metadata and controls
35 lines (28 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Dynamic Layout Draftsman
* Calculates exact header height and updates CSS variables for perfect spacing.
*/
function updateLayout() {
const header = document.querySelector('header');
if (!header) return;
// Get exact height including borders/padding
const headerHeight = header.offsetHeight;
// Set CSS variable on root
document.documentElement.style.setProperty('--header-height', `${headerHeight}px`);
// Debug log
console.log('Layout updated: Header height set to', headerHeight);
}
// Run on load
window.addEventListener('load', updateLayout);
// Run on resize (throttled)
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(updateLayout, 100);
});
// Run immediately if DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', updateLayout);
} else {
updateLayout();
}