Math的数学对象

2018-07-09  本文已影响0人  趁年轻拼一拼

console.log(Math.floor(25.6));//下取整25。

console.log(Math.ceil(25.4));//上取整26。

console.log(Math.random( ));//输出0-1之间的随机小数。

求随机数max,min之间的随机数:

console.log(Math.floor(math.random()*(min-max+1)+max));

练习:随机变换颜色

setInterval(function(){

var div = document.querySelector('.box');

var r = Math.floor(Math.random() * (255));

var g = Math.floor(Math.random() * (255));

var b = Math.floor(Math.random() * (255));

div.style = 'background:rgb(' + r + ',' + g + ',' + b + ')';

console.log(r);

console.log(g);

console.log(b);

},100);

上一篇 下一篇

猜你喜欢

热点阅读