aggiunto gatti salvati
This commit is contained in:
parent
7014349523
commit
9ad5206c56
1 changed files with 35 additions and 2 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
#gatto-casuale {
|
#gatto-casuale {
|
||||||
height: 420px;
|
height: 420px;
|
||||||
}
|
}
|
||||||
#bottone-ricarica {
|
button {
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
background-color: blueviolet;
|
background-color: blueviolet;
|
||||||
padding: 6px;
|
padding: 6px;
|
||||||
|
|
@ -21,19 +21,36 @@
|
||||||
#bottone-ricarica:hover {
|
#bottone-ricarica:hover {
|
||||||
border: 3px solid black;
|
border: 3px solid black;
|
||||||
}
|
}
|
||||||
|
#gatti-salvati {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-around;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
#gatti-salvati img {
|
||||||
|
height: 200px;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="centrato">
|
<div class="centrato">
|
||||||
<button id="bottone-ricarica">Ricarica gatto</button></br></br>
|
<button id="bottone-ricarica">Ricarica gatto</button>
|
||||||
|
<button id="bottone-salva">Salva</button></br></br>
|
||||||
<img id="gatto-casuale" src="" alt="Gatto casuale">
|
<img id="gatto-casuale" src="" alt="Gatto casuale">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="gatti-salvati">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const immagine = document.getElementById("gatto-casuale");
|
const immagine = document.getElementById("gatto-casuale");
|
||||||
const bottone = document.getElementById("bottone-ricarica");
|
const bottone = document.getElementById("bottone-ricarica");
|
||||||
|
const bottoneSalva = document.getElementById("bottone-salva");
|
||||||
|
const salvati = document.getElementById("gatti-salvati");
|
||||||
|
|
||||||
|
let arrayGatti = [];
|
||||||
|
|
||||||
async function getRandomCat() {
|
async function getRandomCat() {
|
||||||
const url = "https://cataas.com/cat?json=true";
|
const url = "https://cataas.com/cat?json=true";
|
||||||
|
|
@ -51,6 +68,22 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bottoneSalva.addEventListener("click", () => {
|
||||||
|
arrayGatti.push(immagine.src);
|
||||||
|
renderizzaGatti();
|
||||||
|
});
|
||||||
|
|
||||||
|
function renderizzaGatti() {
|
||||||
|
salvati.innerHTML = ""; // svuoto il div con i gatti salvati
|
||||||
|
|
||||||
|
// riempiamo con tutti i gatti nell'array
|
||||||
|
for (let i=0; i<arrayGatti.length; i++) {
|
||||||
|
const nuovoGatto = document.createElement("img");
|
||||||
|
nuovoGatto.src = arrayGatti[i];
|
||||||
|
salvati.appendChild(nuovoGatto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
bottone.addEventListener("click", () => {
|
bottone.addEventListener("click", () => {
|
||||||
getRandomCat();
|
getRandomCat();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue