微信小程序?qū)崿F(xiàn)翻牌小功能
本文實(shí)例為大家分享了微信小程序翻牌小功能,供大家參考,具體內(nèi)容如下
頁面
<view id="container"> ? ? <view wx:for="{{newArr}}" class='cards'> ? ? ? ? <view class="card card_a" style='display:{{item.showA}}' bindtap='change' data-id='{{item.id}}'>A</view> ? ? ? ? <view class="card card_b" style='display:{{item.showB}}' bindtap='change' data-id='{{item.id}}'>B</view> ? ? </view> </view>
css
#container { ? ? width: 100%; ? ? height: 350rpx; } .cards { ? ? width: 350rpx; ? ? height: 100%; ? ? margin: 10rpx; ? ? float: left; ? ? } .card { ? ? width: 100%; ? ? height: 100%; ? ? margin: 0 auto; ? ? overflow: hidden; } .card_a { ? ? background-color: pink; } .card_b { ? ? background-color: green; }
js
Page({ ? ? /** ? ? ?* 頁面的初始數(shù)據(jù) ? ? ?*/ ? ? data: { ? ? ? ? newArr: [{ ? ? ? ? ? ? ? ? id: 1, ? ? ? ? ? ? ? ? showA: 'block', ? ? ? ? ? ? ? ? showB: 'none', ? ? ? ? ? ? }, ? ? ? ? ? ? { ? ? ? ? ? ? ? ? id: 2, ? ? ? ? ? ? ? ? showA: 'block', ? ? ? ? ? ? ? ? showB: 'none', ? ? ? ? ? ? }, ? ? ? ? ? ? { ? ? ? ? ? ? ? ? id: 3, ? ? ? ? ? ? ? ? showA: 'block', ? ? ? ? ? ? ? ? showB: 'none', ? ? ? ? ? ? }, { ? ? ? ? ? ? ? ? id: 4, ? ? ? ? ? ? ? ? showA: 'block', ? ? ? ? ? ? ? ? showB: 'none', ? ? ? ? ? ? } ? ? ? ? ], ? ? ? ? firstClickId: 0 ? ? }, ?? ?//點(diǎn)擊切換卡片 ? ? change: function(e) { ? ? ? ? var id = e.currentTarget.dataset.id; ? ? ? ? this.data.firstClickId = id; ? ? ? ? var newArr = this.data.newArr; ? ? ? ? //得到當(dāng)前的卡片 ? ? ? ? var currentData = newArr[id - 1]; ? ? ? ? if (currentData.showA == 'block') { ? ? ? ? ? ? currentData.showA = 'none'; ? ? ? ? ? ? currentData.showB = 'block'; ? ? ? ? ? ? newArr[id - 1] = currentData; ? ? ? ? ? ? this.setData({ ? ? ? ? ? ? ? ? newArr: newArr ? ? ? ? ? ? }) ? ? ? ? } else { ? ? ? ? ? ? currentData.showA = 'block'; ? ? ? ? ? ? currentData.showB = 'none'; ? ? ? ? ? ? newArr[id - 1] = currentData; ? ? ? ? ? ? this.setData({ ? ? ? ? ? ? ? ? newArr: newArr ? ? ? ? ? ? }) ? ? ? ? } ? ? }, })
上面是最簡單的翻牌效果,是沒有3d效果的。就是單純的點(diǎn)擊切換。但是是可以點(diǎn)一張切換一張的。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
根據(jù)地區(qū)不同顯示時(shí)間的javascript代碼
根據(jù)地區(qū)不同顯示時(shí)間的javascript代碼...2007-08-08利用js實(shí)現(xiàn)遮罩以及彈出可移動登錄窗口
本篇文章是對使用js實(shí)現(xiàn)遮罩以及彈出可移動登錄窗口的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-07-07wavesurfer.js繪制音頻波形圖的實(shí)現(xiàn)
這篇文章主要介紹了wavesurfer.js繪制音頻波形圖的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04js原生跨域_用script標(biāo)簽的簡單實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猨s原生跨域_用script標(biāo)簽的簡單實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-09-09JavaScript簡單實(shí)現(xiàn)合并兩個(gè)Json對象的方法示例
這篇文章主要介紹了JavaScript簡單實(shí)現(xiàn)合并兩個(gè)Json對象的方法,結(jié)合實(shí)例形式分析了json對象的遍歷、添加實(shí)現(xiàn)合并的相關(guān)操作技巧,需要的朋友可以參考下2017-10-10