2018.8.12

作者: 喜欢暗杠 | 来源:发表于2018-08-31 12:35 被阅读0次

    Math数学对象

    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);

    相关文章

      网友评论

          本文标题:2018.8.12

          本文链接:https://www.haomeiwen.com/subject/eyeswftx.html