add carousel #4
|
@ -19,7 +19,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-container-inner carousel-container">
|
<div class="flex-container-inner carousel-container">
|
||||||
<div class="carousel"></div>
|
<div id="carousel"></div>
|
||||||
<br>
|
<br>
|
||||||
<div style="margin-left: 10px; font-size: 14px">
|
<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>
|
<a style="color: rgb(73, 73, 73)" href="../assets/js/carousel-items.json">Full list of articles</a>
|
||||||
|
|
|
@ -840,7 +840,7 @@ pre {
|
||||||
padding-left: 80px;
|
padding-left: 80px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.carousel {
|
#carousel {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
|
@ -20,17 +20,26 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
function createCarouselItems(items) {
|
function createCarouselItems(items) {
|
||||||
const carousel = document.querySelector('.carousel');
|
const carousel = document.querySelector('#carousel');
|
||||||
anton marked this conversation as resolved
Outdated
|
|||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const itemDiv = document.createElement('div');
|
const itemDiv = document.createElement('div');
|
||||||
itemDiv.className = 'carousel-item';
|
itemDiv.className = 'carousel-item'
|
||||||
itemDiv.innerHTML = `<a class="carousel-link" target="_blank" rel="noopener noreferrer" href="${item.link}">${item.description}</a>`;
|
|
||||||
anton marked this conversation as resolved
Outdated
ryan
commented
nit: create the nit: create the `<a>` element in code and change the href and innerText manually to avoid XSS
ryan
commented
yes we control both the content and the code but it's a good practice to avoid XSS yes we control both the content and the code but it's a good practice to avoid XSS
|
|||||||
|
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);
|
carousel.appendChild(itemDiv);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeCarousel() {
|
function initializeCarousel() {
|
||||||
const carousel = document.querySelector('.carousel');
|
const carousel = document.querySelector('#carousel');
|
||||||
const items = Array.from(carousel.children);
|
const items = Array.from(carousel.children);
|
||||||
const totalItems = items.length;
|
const totalItems = items.length;
|
||||||
const middleIndex = Math.floor(totalItems / 2);
|
const middleIndex = Math.floor(totalItems / 2);
|
||||||
|
|
Loading…
Reference in New Issue
nit: use an id instead of a class