forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstickyToolbar.js
More file actions
22 lines (18 loc) · 767 Bytes
/
stickyToolbar.js
File metadata and controls
22 lines (18 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Add class to (sticky) toolbar on list view pages when scrolling
export default function handleStickyToolbar() {
const toolbar = document.querySelector('.toolbar');
const header = document.querySelector('.top-bar');
if (!toolbar || !header) {
return;
}
window.addEventListener('scroll', addClassOnScroll);
function addClassOnScroll() {
const toolbarRectTop = toolbar.getBoundingClientRect().top;
const scrolledDistance = window.scrollY;
const clientTop = document.documentElement.clientTop;
const toolbarOffsetTop = toolbarRectTop + scrolledDistance - clientTop;
const headerHeight = header.offsetHeight;
const isToolbarActive = scrolledDistance > toolbarOffsetTop - headerHeight;
toolbar.classList.toggle('active', isToolbarActive);
}
}