思路很简单用 background: rgba({{r}}, {{g}}, {{b}}, {{a}}) 给这四个变量0~255之间的随机整数即可

 html

<view style="height:200px;width: 200px;  background: rgba({{r}}, {{g}}, {{b}}, {{a}})">

</view>
<view class="btn-area">
    <button size="mini" bindtap="tap">changeColour</button>
</view>

js

Page({
  data: {
    r: 150,
    g: 150,
    b: 150,
    a: 150
  },
  tap: function (e) {
    this.setData({
      r: Math.floor(Math.random() * 255),
      g: Math.floor(Math.random() * 255),
      b: Math.floor(Math.random() * 255),
      a: Math.floor(Math.random() * 255),
      
    });
  },
 
})

 

喜欢上方小程序,需要源码的,添加博主微信私信小编.


版权声明:本文为weixin_42460570原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_42460570/article/details/83416541