實(shí)現(xiàn)過程:
1.為該標(biāo)簽綁定點(diǎn)擊事件
1.在點(diǎn)擊事件內(nèi)通過dom獲取到該標(biāo)簽
3.用rgba來改變標(biāo)簽顏色,設(shè)置三個(gè)變量,取隨機(jī)值,
4.通過dom操作實(shí)現(xiàn)動態(tài)為標(biāo)簽綁定顏色
5.將3-4放到定時(shí)器里,(目的是能夠?qū)崿F(xiàn)點(diǎn)擊之后顏色自動變化)
代碼如下:
html:<text @tap="changeColor" class="testOne" :style="{color:current}">點(diǎn)擊連續(xù)改變顏色</text>
js:
changeColor() {
if(this.isClick){
return
}
this.isClick = true
let selectorQuery = uni.createSelectorQuery()
let abc = selectorQuery.select('.testOne')
let that = this
? ? ? ? setInterval(function() {
? ? ? ? ? ? ? ? let first = Math.round(Math.random() * 255);
? ? ? ? ? ? ? ? let second = Math.round(Math.random() * 255);
? ? ? ? ? ? ? ? let third = Math.round(Math.random() * 255);
? ? ? ? ? ? ? ? let color = `rgba(${first},${second},${third},1)`//注意這里是模板字符串``
????????????????that.current = color
? ? ? ? }, 500)
? ? }