2016-08-13 54 views

回答

2
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无法制作随机数字。

https://css-tricks.com/generate-a-random-number/

0

为了使图像广场,并使其反应您使用%设置的大小。

.random image { 
height: 10%; 
width: 10%; 
} 
相关问题