-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (25 loc) · 1.12 KB
/
index.js
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
const bottomBar = document.getElementById("bottombar");
const viewport = window.visualViewport;
const scrolling = document.getElementById("scrolling");
// ref: https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport
function viewportHandler() {
const layoutViewport = document.getElementById("layoutViewport");
const bottomBarHeight = bottomBar.getBoundingClientRect().height;
scrolling.style.height = `${viewport.height - bottomBarHeight}px`;
scrolling.style.bottom = `${bottomBarHeight}px`;
const offsetTop =
viewport.height -
layoutViewport.getBoundingClientRect().height +
viewport.offsetTop;
console.log(viewport, layoutViewport.getBoundingClientRect())
const transformStyle = `translateY(${offsetTop}px)`;
bottomBar.style.transform = transformStyle;
scrolling.style.transform = transformStyle;
}
window.visualViewport.addEventListener("scroll", viewportHandler);
window.visualViewport.addEventListener("resize", viewportHandler);
bottomBar.addEventListener("touchmove", (e) => e.preventDefault(), {
passive: false,
});
document.body.style.minHeight = `${window.innerHeight}px`;
viewportHandler();