小程序?qū)崿F(xiàn)點(diǎn)擊動(dòng)畫效果
本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)點(diǎn)擊動(dòng)畫效果的具體代碼,供大家參考,具體內(nèi)容如下
今天接到一個(gè)小程序優(yōu)化需求,要實(shí)現(xiàn)一個(gè)點(diǎn)擊的動(dòng)畫效果
考慮實(shí)現(xiàn)方法,使用css的transition屬性來進(jìn)行實(shí)現(xiàn),點(diǎn)擊的時(shí)候給css新增一個(gè)active屬性,就能實(shí)現(xiàn)這個(gè)效果了
// html? <view class="list-box"> ?<view class="list {{item.check ? 'active' : ''}}" wx:for="{{listOne}}" data-id="{{item.id}}" wx:key="index" bindtap="bindClick"> ? ? ?<view class="point"> ? ? ? ? ?<image src="../../../img/sure-icon.png" mode="widthFix"/> ? ? ?</view> ? ? ?{{item.name}} ?</view> </view>
// js data: { ?? ?listOne: [ ? ? ? { id: 1, name: '弱音頻', check:false}, ? ? ? { id: 2, name: '中音頻', check:false}, ? ? ? { id: 3, name: '強(qiáng)音頻', check:false} ? ? ] } // 點(diǎn)擊方法 ?bindClick (e) { ? ?let id = e.currentTarget.dataset.id ? ?let listOne = this.data.listOne.map(item => { ? ? ?if(item.id == id ){ ? ? ? ?item.check = true ? ? ? ?// 選中以后需要執(zhí)行的方法 ? ? ?}else { ? ? ? ?item.check = false ? ? ?} ? ? ?return item ? ?})? ? ?this.setData({listOne}) ?},
// css 主要css是在active的位置,其余的可以根據(jù)設(shè)計(jì)稿樣式自己改 .list-box{ ? ? width: 660rpx; ? ? margin: 0 auto; ? ? margin-top: 71rpx; ? ? .list{ ? ? ? ? height: 100rpx; ? ? ? ? background-color: #ffffff; ?? ? ? ?box-shadow: 0rpx 5rpx 9rpx 0rpx rgba(79, 90, 103, 0.09); ? ? ? ? border-radius: 16rpx; ? ? ? ? border: 3px solid transparent; ? ? ? ? transition: all 0.4s; ? ? ? ? position: relative; ? ? ? ? text-align: center; ? ? ? ? line-height: 100rpx; ? ? ? ? font-family: Source Han Sans CN; ? ? ? ? font-size: 36rpx; ? ? ? ? font-weight: bold; ? ? ? ? color: #0f2655; ? ? ? ? margin-bottom: 33rpx; ? ? } ? ? ? ? ? .point { ? ? ? ? position: absolute; ? ? ? ? background: #8bc63e; ? ? ? ? width: 36rpx; ? ? ? ? height: 36rpx; ? ? ? ? bottom: 0; ? ? ? ? right: 0; ? ? ? ? border-radius: 8px 0 0 0px; ? ? ? ? transition: all 0.4s; ? ? ? ? opacity: 0; ? ? image{ ? ? ? ? display: none; ? ? } ? } ? ? .list.active { ? ? ? ? border: 3px ?solid #8bc63e; ? ? // box-shadow:0px 6px 10px 0px rgba(0, 0, 0, 0.3); ? } ? .list.active .list-title{ ? ? ? ? transition: all 0.4s; ? ? ? ? color: #8bc63e; ? } ? .list.active .list-bold{ ? ? ? ? transition: all 0.4s; ? ? ? ? color: #8bc63e; ? ? } ? .list.active ?.point { ? ? ? ? opacity: 1; ? ? ? ? position: absolute; ? ? ? ? background: #8bc63e; ? ? ? ? width: 36rpx; ? ? ? ? height: 36rpx; ? ? ? ? bottom: 0; ? ? ? ? right: 0; ? ? ? ? border-radius: 8px 0 0 0px; ? } ? .list.active ?.point image{ ? ? ? ? // transition: all 0.3s; ? ? ? ? display: block; ? ? ? ? width: 19rpx; ? ? ? ? height: 14rpx; ? ? ? ? margin-top: 14rpx; ? ? ? ? margin-left: 12rpx; ? } }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
微信小程序 子級(jí)頁面返回父級(jí)并把子級(jí)參數(shù)帶回父級(jí)實(shí)現(xiàn)方法
這篇文章主要介紹了微信小程序 子級(jí)頁面返回父級(jí)并把子級(jí)參數(shù)帶回父級(jí)實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08在JavaScript中使用嚴(yán)格模式(Strict Mode)
這篇文章主要介紹了在JavaScript中使用嚴(yán)格模式(Strict Mode),除了正常運(yùn)行模式,ECMAscript 5添加了第二種運(yùn)行模式:"嚴(yán)格模式"(strict mode)。顧名思義,這種模式使得Javascript在更嚴(yán)格的條件下運(yùn)行。,需要的朋友可以參考下2019-06-06JavaScript欄目列表隱藏/顯示簡單實(shí)現(xiàn)
隱藏側(cè)邊欄,并將圖片換成右箭頭圖片;顯示側(cè)邊欄,并將圖片換成左箭頭,這樣的效果想必大家都很熟悉吧,接下來實(shí)現(xiàn)下,感興趣的朋友可以參考下哈2013-04-04使用javascript獲取flash加載的百分比的實(shí)現(xiàn)代碼
使用javascript獲取flash加載的百分比的實(shí)現(xiàn)代碼,方便flash小游戲判斷頁面,提高用戶體驗(yàn)。2011-05-05JS?Angular?服務(wù)器端渲染應(yīng)用設(shè)置渲染超時(shí)時(shí)間???????
這篇文章主要介紹了JS?Angular服務(wù)器端渲染應(yīng)用設(shè)置渲染超時(shí)時(shí)間,???????通過setTimeout模擬一個(gè)需要5秒鐘才能完成調(diào)用的API展開詳情,需要的小伙伴可以參考一下2022-06-06JS 學(xué)習(xí)總結(jié)之正則表達(dá)式的懶惰性和貪婪性
這篇文章主要介紹了JS 學(xué)習(xí)總結(jié)之正則表達(dá)式的懶惰性和貪婪性的相關(guān)資料,需要的朋友可以參考下2017-07-07