1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| "use strict";
function randomImg( figure_id )
{
let random_images = [
{
"url" : "https://www.museumtv.art/wp-content/uploads/2017/08/ceci-nest-pas-une-pipe1-e1502441198132.jpg",
"txt" : "Ceci n'est pas une pipe",
},
{
"url" : "https://www.museumtv.art/wp-content/uploads/2017/08/ceci-nest-pas-une-pipe-parodie-magritte-02.jpg",
"txt" : "Sel ou poivre ?",
},
// ....
];
let random_index = Math.floor(Math.random() * random_images.length);
document.querySelector( figure_id + ' img' ).src = random_images[random_index].url;
document.querySelector( figure_id + ' img' ).alt = random_images[random_index].txt;
document.querySelector( figure_id + ' figcaption' ).textContent = random_images[random_index].txt;
}
window.addEventListener("DOMContentLoaded", (event) => {
randomImg('#randomImg');
}); |
Partager