我希望用户查看其分数2秒后重新加载页面(游戏重新启动)。另外,可以为显示的形状设置最小和最大高度。
const start = new Date();
const x = Math.floor(Math.random() * 256);
const y = Math.floor(Math.random() * 256);
const z = Math.floor(Math.random() * 256);
const bgColor = "rgb(" + x + "," + y + "," + z + ")";
const shape = document.querySelector("#shape");
const generateShape = () => {
const shape = document.querySelector("#shape");
shape.style.height = Math.floor(Math.random() * 250) + "px";
shape.style.width = Math.floor(Math.random() * 250) + "px";
shape.style.borderRadius = Math.floor(Math.random() * 100) + "%";
shape.style.margin = Math.floor(Math.random() * 300) + "px";
shape.style.backgroundColor = bgColor;
}
const getTime = () => {
shape.style.display = "none";
const stop = new Date();
const timeDiff = stop.getTime() - start.getTime();
const writeTime = document.querySelector("#span");
writeTime.innerHTML = timeDiff / 1000 + " s"
}
shape.addEventListener("click", getTime);
generateShape();