RetroDECK-Website/scripts/features.js

26 lines
975 B
JavaScript
Raw Normal View History

const featureCardElems = document.getElementsByClassName('feature-card');
const featureCardContainerElem = document.getElementById('feature-card-container');
let currentFeatureCard = 1
2024-04-23 16:16:44 +00:00
for (let i = 0; i < featureCardElems.length; i++) {
featureCardElems[i].addEventListener('click', function() {
if (i != currentFeatureCard) {
updateActiveFeatureCard(i);
2024-04-24 13:53:04 +00:00
}
2024-04-23 16:16:44 +00:00
}, false)
}
function updateActiveFeatureCard(i) {
const lastCurrentFeature = currentFeatureCard;
currentFeatureCard = i;
console.log(i)
featureCardElems[i].id = 'active-feature-card';
featureCardElems[lastCurrentFeature].id = "";
if (lastCurrentFeature < i) {
// featureCardContainerElem.scrollLeft = featureCardElems[i].offsetLeft - featureCardElems[i].offsetWidth/2
featureCardContainerElem.scrollIntoView
} else {
featureCardContainerElem.scrollLeft = featureCardElems[i].offsetLeft - featureCardElems[i].offsetWidth
2024-06-18 17:17:39 +00:00
}
}