-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (34 loc) · 1.71 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
document.addEventListener("DOMContentLoaded", function () {
function changeStep(stepNumber) {
const searchParams = new URLSearchParams(window.location.search);
const activeStepNumber = searchParams.get('step') || 0;
const steps = document.querySelectorAll('.step-swtich-button');
// const activeStepNumber = [...steps].findIndex((stepButton) => stepButton.classList.contains('step-swtich-button-active'));
const activeStep = steps[activeStepNumber];
activeStep.classList.remove('step-swtich-button-active');
const pressedStep = steps[stepNumber];
pressedStep.classList.add('step-swtich-button-active');
const images = document.querySelectorAll('.image-wrapper');
const activeImage = images[activeStepNumber];
activeImage.classList.remove('image-wrapper-active');
const pressedImageStep = images[stepNumber];
pressedImageStep.classList.add('image-wrapper-active');
const url = new URL(window.location)
url.searchParams.set("step", String(stepNumber))
history.pushState(null, '', url);
}
function assignButtonHandlers() {
const steps = document.querySelectorAll('.step-swtich-button');
const searchParams = new URLSearchParams(window.location.search);
const activeStepNumber = searchParams.get('step') || 0;
const activeStepButton = steps[activeStepNumber];
activeStepButton.classList.add('step-swtich-button-active');
const images = document.querySelectorAll('.image-wrapper');
const activeStepImage = images[activeStepNumber];
activeStepImage.classList.add('image-wrapper-active');
steps.forEach((button, idx) => {
button.onclick = () => changeStep(idx)
})
}
assignButtonHandlers()
});