forked from jgthms/bulma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
klmn.js
40 lines (32 loc) · 966 Bytes
/
klmn.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
40
document.addEventListener('DOMContentLoaded', () => {
const $klmnColumns = Array.prototype.slice.call(document.querySelectorAll('.bd-klmn-columns'), 0);
const $klmnGaps = Array.prototype.slice.call(document.querySelectorAll('.bd-klmn-gap'), 0);
const $klmnValue = document.getElementById('klmnValue');
$klmnGaps.forEach(el => {
el.addEventListener('mouseenter', () => {
const index = el.dataset.value;
selectGap(index);
});
});
function resetGaps() {
$klmnGaps.forEach(el => {
el.classList.remove('bd-is-selected');
});
}
function setColumns(n) {
$klmnColumns.forEach(el => {
el.className = `columns is-variable bd-klmn-columns is-${n}`;
});
}
function setValue(n) {
const rem = `${n * 0.25}rem`;
$klmnValue.innerHTML = rem;
}
function selectGap(n) {
resetGaps();
$klmnGaps[n].classList.add('bd-is-selected');
setColumns(n);
setValue(n);
}
selectGap(3);
});