-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
39 lines (35 loc) · 1.14 KB
/
main.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
32
33
34
35
36
37
38
39
const ready = () => {
// package selector for mobile
const buttons = Array.from(
document.querySelectorAll('.pkg-mobile-selector__button')
);
const container = document.querySelector('.pkg-container');
buttons.map(button => {
button.addEventListener('click', event => {
const package = event.target.dataset.package;
container.dataset.package = package;
});
});
// info button in table
const infoButtons = Array.from(
document.querySelectorAll('.pkg-table__more-info')
);
infoButtons.map(button => {
button.addEventListener('click', event => {
event.target.classList.toggle('active');
});
});
const selector = document.querySelector('.pkg-mobile-selector');
const table = document.querySelector('.pkg-table');
const scrollListener = event => {
const rect = table.getBoundingClientRect();
if (rect.top < -50 && rect.bottom > 50) {
selector.classList.add('sticky');
} else {
selector.classList.remove('sticky');
}
};
window.addEventListener('scroll', scrollListener, { passive: true });
scrollListener();
};
document.addEventListener('DOMContentLoaded', ready);