思路很简单用 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),
});
},
})
喜欢上方小程序,需要源码的,添加博主微信私信小编.