-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboutMeScript.js
More file actions
40 lines (38 loc) · 1.25 KB
/
Copy pathAboutMeScript.js
File metadata and controls
40 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// read data from json files
async function getData(jsonName) {
let response = await fetch(`data/${jsonName}.json`);
let data = await response.json();
return data;
}
(async function() {
// get data from json files
const cardsData = await getData("CardsData");
// create HTML code for each card
const cardsHTML=[];
for(let i=0; i<cardsData.length; i++){
cardsHTML.push(createCardHTML(cardsData[i],i));
}
// add cards to the page
const cardsContainer = document.getElementById('cards-container');
cardsContainer.innerHTML = cardsHTML.join('');
// add event listener to each card
const cards = document.getElementsByClassName("card")
for(let i=0; i<cards.length; i++){
cards[i].addEventListener("click", function(){
localStorage.setItem('index', i);
window.location.href = "/DetailPage";
});
}
})();
// generate HTML code for each card
function createCardHTML(cardData,index) {
return `
<div class="card" id="card${index}">
<div class="card-details">
<p class="text-title">${cardData.title}</p>
<p class="text-body">${cardData.content}</p>
</div>
<button class="card-button">More info</button>
</div>
`;
}