Сообщение от Pavel7558
|
Ай да и как тут примянить массив и зачем он вообще?
|
Нужен для списка шести картинок.
<body><script>
const images = [
{
image: "https://i.picsum.photos/id/237/500/500.jpg",
thumbnail: "https://i.picsum.photos/id/237/100/100.jpg"
},
{
image: "https://i.picsum.photos/id/238/500/500.jpg",
thumbnail: "https://i.picsum.photos/id/238/100/100.jpg"
},
{
image: "https://i.picsum.photos/id/239/500/500.jpg",
thumbnail: "https://i.picsum.photos/id/239/100/100.jpg"
},
{
image: "https://i.picsum.photos/id/240/500/500.jpg",
thumbnail: "https://i.picsum.photos/id/240/100/100.jpg"
},
{
image: "https://i.picsum.photos/id/241/500/500.jpg",
thumbnail: "https://i.picsum.photos/id/241/100/100.jpg"
},
{
image: "https://i.picsum.photos/id/242/500/500.jpg",
thumbnail: "https://i.picsum.photos/id/242/100/100.jpg"
}
];
const keys = Object.keys(images);
const randomKeys = [];
while(randomKeys.length < 2) {
randomKeys.push(...keys.splice(Math.floor(keys.length * Math.random()), 1));
}
for(const key of randomKeys) {
const { thumbnail, image } = images[key];
const link = document.createElement("a");
link.href = image;
link.target = "_blank";
const imageEl = new Image();
imageEl.src = thumbnail;
link.appendChild(imageEl);
document.body.appendChild(link);
}
</script>