首页
   /       /   
小程序随机颜色显示
9月
12
小程序随机颜色显示
作者:大彭Sir    分类: 教学教程

JS代码

//储存随机颜色
data: {
    colorArr: ["#EE2C2C", "#ff7070", "#EEC900", "#4876FF", "#ff6100",
      "#7DC67D", "#E17572", "#7898AA", "#C35CFF", "#33BCBA", "#C28F5C",
      "#FF8533", "#6E6E6E", "#428BCA", "#5cb85c", "#FF674F", "#E9967A",
      "#66CDAA", "#00CED1", "#9F79EE", "#CD3333", "#FFC125", "#32CD32",
      "#00BFFF", "#68A2D5", "#FF69B4", "#DB7093", "#CD3278", "#607B8B"],
    randomColorArr: [],
    labLen:'',
    good:''
  }

判断代码

//判断
var gudong = that.data.gudong
    var labLen = gudong.length,
      colorArr = that.data.colorArr,
      colorLen = colorArr.length,
      randomColorArr = [];

    //判断执行
    for (var i = 0; i <= colorLen;i++) {
      let random = colorArr[Math.floor(Math.random() * colorLen)];
      console.log(random)
      randomColorArr.push(random);
    }

    that.setData({
      randomColorArr: randomColorArr
    });
    console.log(randomColorArr)

WXML代码

<view data-key="{{key}}" style="background:{{randomColorArr[key]}}">{{item.upshow}}</view>
本文标签:标签: 小程序
责任声明:本页信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!
转载声明:本文作者大彭Sir,如需转载请保留文章出处!原文链接请自行复制!

Theme By Brief 鄂ICP备19010459号
sitemap