forked from mi-classroom/webdev-fd-sose-2024-fd-2024-prufung-startercode-fd-2024-pruefung-startercode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyJS.js
72 lines (57 loc) · 2.21 KB
/
myJS.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Gpt Code
fetch("works.json")
.then((response) => response.json())
.then((data) => {
const works = data.slice(0, 5);
const workGrid = document.querySelector(".work-grid");
works.forEach((work) => {
const workItem = document.createElement("div");
workItem.classList.add("work-item");
const image = document.createElement("img");
image.src = work.image;
image.alt = work.title;
const content = document.createElement("div");
content.classList.add("content");
const title = document.createElement("h3");
title.textContent = work.title;
const description = document.createElement("p");
description.textContent = work.description;
content.appendChild(title);
content.appendChild(description);
workItem.appendChild(image);
workItem.appendChild(content);
workGrid.appendChild(workItem);
});
// Füge den Button "Mehr Arbeiten" hinzu
const moreButton = document.createElement("button");
moreButton.textContent = "Mehr Arbeiten";
moreButton.className = "simple-button";
moreButton.addEventListener("click", () => {
// Lade alle Arbeiten und zeige sie an
fetch("works.json")
.then((response) => response.json())
.then((data) => {
workGrid.innerHTML = "";
data.forEach((work) => {
const workItem = document.createElement("div");
workItem.classList.add("work-item");
const image = document.createElement("img");
image.src = work.image;
image.alt = work.title;
const content = document.createElement("div");
content.classList.add("content");
const title = document.createElement("h3");
title.textContent = work.title;
const description = document.createElement("p");
description.textContent = work.description;
content.appendChild(title);
content.appendChild(description);
workItem.appendChild(image);
workItem.appendChild(content);
workGrid.appendChild(workItem);
});
moreButton.style.display = "none";
});
});
workGrid.appendChild(moreButton);
});