Untitled
unknown
plain_text
a year ago
1.4 kB
4
Indexable
let clickCount = 0;
const maxClicks = {
desktop: 1,
tablet: 2,
mobile: 4,
};
const stepClassNames = ['eg-step1', 'eg-step2', 'eg-step3', 'eg-step4', 'eg-step5'];
const updateClickCountFromClass = () => {
const currentClass = Array.from(document.body.classList).find(className =>
stepClassNames.includes(className)
);
if (currentClass) {
clickCount = stepClassNames.indexOf(currentClass);
}
};
const updateClass = () => {
document.body.className = '';
const stepToAdd = Math.min(clickCount, stepClassNames.length - 1);
document.body.classList.add(stepClassNames[stepToAdd]);
};
const handleNextClick = () => {
updateClickCountFromClass();
const currentMaxClicks = determineMaxClicks();
if (clickCount < currentMaxClicks) {
clickCount++;
updateClass();
}
};
const handlePrevClick = () => {
updateClickCountFromClass();
if (clickCount > 0) {
clickCount--;
updateClass();
}
};
const determineMaxClicks = () => {
if (window.innerWidth <= 768) {
return maxClicks.mobile;
} else if (window.innerWidth <= 1024) {
return maxClicks.tablet;
} else {
return maxClicks.desktop;
}
};Editor is loading...
Leave a Comment