uniapp實(shí)現(xiàn)點(diǎn)擊標(biāo)簽,標(biāo)簽內(nèi)容的顏色不斷改變(vue也同樣適用)

實(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)

? ? }

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容