add carousel #4

Manually merged
anton merged 3 commits from carousel into main 2024-03-28 23:21:50 +00:00
3 changed files with 18 additions and 9 deletions
Showing only changes of commit 5b284e2eed - Show all commits

View File

@ -19,7 +19,7 @@
</div>
</div>
<div class="flex-container-inner carousel-container">
<div class="carousel"></div>
<div id="carousel"></div>
<br>
<div style="margin-left: 10px; font-size: 14px">
<a style="color: rgb(73, 73, 73)" href="../assets/js/carousel-items.json">Full list of articles</a>

View File

@ -840,7 +840,7 @@ pre {
padding-left: 80px;
}
.carousel {
#carousel {
display: flex;
flex-direction: column;
align-items: center;

View File

@ -20,17 +20,26 @@ document.addEventListener('DOMContentLoaded', function () {
});
function createCarouselItems(items) {
const carousel = document.querySelector('.carousel');
const carousel = document.querySelector('#carousel');
items.forEach(item => {
const itemDiv = document.createElement('div');
itemDiv.className = 'carousel-item';
itemDiv.innerHTML = `<a class="carousel-link" target="_blank" rel="noopener noreferrer" href="${item.link}">${item.description}</a>`;
itemDiv.className = 'carousel-item'
const link = document.createElement('a');
link.className = 'carousel-link';
link.href = item.link;
link.target = '_blank';
link.rel = 'noopener noreferrer';
const linkText = document.createTextNode(item.description);
link.appendChild(linkText);
itemDiv.appendChild(link);
carousel.appendChild(itemDiv);
});
}
function initializeCarousel() {
const carousel = document.querySelector('.carousel');
const carousel = document.querySelector('#carousel');
const items = Array.from(carousel.children);
const totalItems = items.length;
const middleIndex = Math.floor(totalItems / 2);
@ -45,12 +54,12 @@ function initializeCarousel() {
items.forEach((item, index) => {
let positionIndex = (currentIndex + index + totalItems) % totalItems;
let offset = positionIndex - middleIndex;
item.style.transform = `translateY(${offset * 100}%)`;
item.style.transform = `translateY(${offset * 100}%)`;
item.classList.toggle('active', positionIndex === middleIndex);
item.style.visibility = 'visible';
item.style.visibility = 'visible';
});
}
updateCarouselItems();
setInterval(cycleItems, 7000);
setInterval(cycleItems, 7000);
}