You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.7 KiB
83 lines
2.7 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
<title>Obrazek dne</title>
|
|
<style>
|
|
#obrazek img {
|
|
width: 10%;
|
|
height: auto;
|
|
}
|
|
#obrazek-sam img {
|
|
width: 10%;
|
|
height: auto;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<h1> Obrázek dne </h1>
|
|
<h2> Zadání vytvořte soubor JSON, který umístíte do adresáře projektu
|
|
Obsah: název souboru/obrázek a popisek (motto)
|
|
Napiste kod který stahne jsoun soubor a sna stánce zobrazi obrázek získaný z json souboru a popisek (textovací informace).
|
|
</h2>
|
|
|
|
<div>
|
|
<div id="obrazek"> </div>
|
|
<div id="text"> </div>
|
|
|
|
<div id="obrazek-sam"> </div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script src="jquery-3.5.1.min.js"></script>
|
|
<script>
|
|
$.getJSON("/data.json")
|
|
.done(function(data) {
|
|
console.log(data);
|
|
console.log(data.text_s);
|
|
console.log(data.obrazek_s);
|
|
let div = $("#obrazek")
|
|
let p = $("#text")
|
|
for (let index = 0; index < data.text_s.length; index++) {
|
|
const tx = data.text_s[index];
|
|
p.append("<label>" + tx + "</label>")
|
|
}
|
|
for (let index = 0; index < data.obrazek_s.length; index++) {
|
|
const obr = data.obrazek_s[index];
|
|
div.append("<img src='images/" + obr + "' >")
|
|
}
|
|
|
|
|
|
})
|
|
.fail(function() {
|
|
console.log("chyba");
|
|
alert("Chyba se řeší")
|
|
})
|
|
.always(function() {
|
|
console.log("Vždycky")
|
|
});
|
|
function stahniObrazek () {
|
|
$.getJSON("/data.json")
|
|
.done(function(data) {
|
|
let puvodni = $("#obrazek-sam img").attr("src");
|
|
console.log(puvodni);
|
|
if (puvodni != data.obrazek) {
|
|
$("#obrazek-sam").html("<img src='" + data.obrazek + "' >").append("<label>" + data.text + "</label>");
|
|
}
|
|
})
|
|
}
|
|
window.setInterval(stahniObrazek, 5000)
|
|
</script>
|
|
</body>
|
|
</html>
|