-
Notifications
You must be signed in to change notification settings - Fork 1
/
window_resize.html
48 lines (48 loc) · 1.2 KB
/
window_resize.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<title>Div resize with Window resize</title>
</head>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
.header{
width: 100%;
display: flex;
background-color: brown;
}
.content{
width: 100%;
background-color: black;
display: flex;
}
.footer {
width: 100%;
display: flex;
height: 50px;
background-color: blue;
}
</style>
<body>
<div class="header">
<h2>Div resize with Window resize</h2>
</div>
<div class="content"></div>
<div class="footer"></div>
<script>
const divResize = (h, c, f) => {
const w_height = window.innerHeight;
const h_height = document.querySelector('.'+h).offsetHeight;
const f_height = document.querySelector('.'+f).offsetHeight;
const c_height = w_height - (h_height + f_height);
console.log(w_height, c_height);
document.querySelectorAll('.'+c)[0].style.height = c_height + 'px';
};
// Attaching the event listener function to window's resize event
window.addEventListener("resize", divResize('header', 'content', 'footer'));
</script>
</body>
</html>