Képek fetchelése, megjelenítése

This commit is contained in:
Kovács Rudolf committed 2026-11-04 10:54:51 +01:00
1 parent b4e90847af
commit adb084d676
2 files changed
+44

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
let root=document.getElementById('root');
let kontener=document.createElement('div');
//kontener.setAttribute('class','flex flex-row flex-wrap items-center justify-center bg-sky-200');
kontener.setAttribute('class','grid lg:grid-cols-4 md:grid-cols-2 sm:grid-cols-1 justify-items-center bg-sky-200');
fetch('https://jsonplaceholder.typicode.com/photos')
.then(res=>res.json())
.then(adat=>{
//console.log(adat)
adat.forEach(kep => {
let kepkontener=document.createElement('div');
kepkontener.setAttribute('class','flex flex-col items-center justify-center rounded-xl w-96 bg-sky-400 m-2 p-2');
let title=document.createElement('p');
title.setAttribute('class','text-2xl text-center text-sky-800');
title.textContent=kep.title;
let image=document.createElement('img');
image.setAttribute('class','rounded-xl w-96')
image.src=kep.url;
kepkontener.appendChild(image);
kepkontener.appendChild(title);
kontener.appendChild(kepkontener);
});
})
.catch(err=>alert(err));
root.appendChild(kontener);
+17
View File
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="hu">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script defer src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<script defer src="fetch.js"></script>
<title>Fetch használata</title>
</head>
<body>
<h1 class="text-5xl text-center font-bold bg-sky-200 p-2">Fetch használata</h1>
<div id="root">
</div>
</body>
</html>