Feature Titles now scrolls when horizontal and tapped/clicked

This commit is contained in:
Adam Iannazzone 2024-04-24 13:10:15 -04:00
parent 81871def2b
commit 86af6cdabc
2 changed files with 14 additions and 0 deletions

View file

@ -69,6 +69,10 @@ footer {
background: #333;
}
#feature-list {
scrollbar-width: none;
}
.feature-list-item {
padding: 0.5rem;
cursor: pointer;

View file

@ -1,5 +1,6 @@
const featureTitles = document.getElementsByClassName('feature-list-item');
const featureDetails = document.getElementsByClassName('feature-detail-container');
const featureList = document.getElementById('feature-list');
let currentFeature = 0;
for (let i = 0; i < featureTitles.length; i++) {
@ -18,6 +19,7 @@ for (let i = 0; i < featureTitles.length; i++) {
function updateActiveFeature(i) {
const lastCurrentFeature = currentFeature;
currentFeature = i;
// console.log(`${lastCurrentFeature} -> ${currentFeature}`);
// New current feature
featureTitles[currentFeature].className += ' gradient-spin my-gradient';
@ -30,4 +32,12 @@ function updateActiveFeature(i) {
featureTitles[lastCurrentFeature].style = '';
featureDetails[lastCurrentFeature].removeAttribute('id');
// Update scroll position
const offsetPadding = 20;
if (lastCurrentFeature < currentFeature) {
featureList.scrollLeft = featureTitles[currentFeature].offsetLeft - offsetPadding;
} else {
featureList.scrollLeft = featureTitles[currentFeature].offsetLeft - featureTitles[currentFeature].offsetWidth/2 - offsetPadding;
}
}