如何使随机大小的图像元素成为正方形并且响应迅速?
最佳答案
element.style.height = Math.floor(Math.random() * 101) + "%";
element.style.width = Math.floor(Math.random() * 101) + "%";
Math.floor() 返回小于或等于给定数的最大整数
Math.random() 返回一个介于 0 和 1 之间的数字。
请注意,我们使用的是 JavaScript,因为 HTML/CSS 无法生成随机数。
关于html - 如何制作随机大小的图像元素正方形并且响应迅速(%宽度而不是像素)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38934382/