Generate random food images in a slideshow
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>版本7 - 圖片輪播</title>
<style>
#result { font-size: 2em; margin: 20px; }
button { padding: 10px 20px; }
</style>
</head>
<body>
<button onclick="draw()">開始抽籤</button><br>
<img id="foodImg" src="https://pic.pngsucai.com/00/87/05/9e1c2cdce2519ccc.webp" width="200">
<script>
const foods = [
{name: "便當", img: "https://pic.pngsucai.com/00/87/05/9e1c2cdce2519ccc.webp"},
{name: "炒飯", img: "https://pic.pngsucai.com/01/01/22/b8c1752bff44f5d1.webp"},
{name: "牛肉麵", img: "https://pic.pngsucai.com/00/97/95/35f4d876b11ed68f.webp"}
];
function draw() {
let count=0;
const interval=setInterval(()=>{
const pick = foods[Math.floor(Math.random()*foods.length)];
document.getElementById("foodImg").src = pick.img;
count++;
if(count>15) clearInterval(interval);
},100);
}
</script>
</body>
</html>