微信小程序?qū)崿F(xiàn)九宮格翻牌動(dòng)畫
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)九宮格翻牌的具體代碼,供大家參考,具體內(nèi)容如下
9宮格翻牌需求:
1.進(jìn)來(lái)時(shí)平鋪9個(gè)格子顯示
2.點(diǎn)擊開(kāi)始抽獎(jiǎng)時(shí)洗牌動(dòng)作
3.洗完牌后呈現(xiàn)9個(gè)都是未翻牌的狀態(tài)
4.點(diǎn)擊任意一個(gè)牌子,有翻轉(zhuǎn)的動(dòng)作
5.翻轉(zhuǎn)結(jié)束后出現(xiàn)中獎(jiǎng)的彈窗
555,當(dāng)時(shí)真的一點(diǎn)一點(diǎn)調(diào)動(dòng)畫
敲黑板~
wxml:
<view class="main_border"> <view class="inside_border viewport-flip"> <block wx:for="{{position}}"> <view class="parent_border flip {{flipArr[index]?'out':'in'}}" style="left:{{item.x}};top:{{item.y}};" animation="{{objArr[index].animationData}}" data-idx="{{index}}" hover-class="opacity"> <form report-submit class="sec_border border_{{index}} gifts_back centerBtn" bindsubmit="{{isMember?'click':'openCard'}}" style="display:block" wx:if="{{isClick && index ==4}}"> <button class="" form-type="submit" style="width:100%;height:100%;opacity:0"></button> </form> <view class="sec_border border_{{index}} gifts_back {{isClick?'centerBtn':''}}" bindtap="{{isClick?'':'btnFlip'}}" data-index="{{index}}" wx:else> </view> </view> </block> </view> </view>
less: 動(dòng)畫基本上我是用添加class類樣式控制的
.main_border{ ? .inside_border{ ? ? margin: 0 auto; ? ? width: 639rpx; ? ? height: 639rpx; ? ? position: relative; ? ? ? ? .parent_border{ ? ? ? position:absolute; ? ? ? height:203rpx; ? ? ? width: 203rpx; ? ? } ? } } ? .sec_border{ ? ? width: 100%; ? ? height: 100%;? ? .gifts_img{ ? ? display:none; ? ? width: 100%; ? ? height: 100%; ? ?? ? } } ? .gift-animat{ ? ? display: block; } ? ? ? // 翻牌動(dòng)畫 .viewport-flip { ? ? -webkit-perspective: 1000; ? ? perspective: 1000; ? ? position: absolute; } .flip { ? ? -webkit-backface-visibility: hidden; ? ? -webkit-transform: translateX(0); /* Needed to work around an iOS 3.1 bug that causes listview thumbs to disappear when -webkit-visibility:hidden is used. */ ? ? backface-visibility: hidden;/*backface-visibility 屬性定義當(dāng)元素不面向屏幕時(shí)是否可見(jiàn)*/ ? ? transform: translateX(0); ? ? position: fixed; } .flip.out { ? ? -webkit-transform: rotateY(-90deg) scale(.9); ? ? -webkit-animation-name: flipouttoleft; ? ? -webkit-animation-duration: 175ms; ? ? transform: rotateY(-90deg) scale(.9); ? ? animation-name: flipouttoleft; ? ? animation-duration: 175ms; } ? .flip.in { ? ? -webkit-animation-name: flipintoright; ? ? -webkit-animation-duration: 225ms; ? ? animation-name: flipintoright; ? ? animation-duration: 225ms; } ? @keyframes flipouttoleft { ? ? from { -webkit-transform: rotateY(0); } ? ? to { -webkit-transform: rotateY(-90deg) scale(.9); } } ? .flip.outA { ? ? // -webkit-transform: rotateY(-90deg) scale(.9); ? ? // -webkit-animation-name: flipouttoleft; ? ? // -webkit-animation-duration: 175ms; ? ? transform: rotateY(0deg) scale(1); ? ? animation-name: flipouttoleftA; ? ? animation-duration: 1000ms;? ? ? top:0 !important; ? ? left: 0 !important; ? ? width: 640rpx !important; ? ? height: 700rpx !important; ? ? z-index: 999999; } @keyframes flipouttoleftA { ? ? 0% {? ? ? ? ? transform: rotateY(0);? ? ? } ? ? 50% { ? ? ? ?transform: rotateY(-90deg) scale(1); ? ? ? } ? ? 100% {? ? ? ? ? transform: rotateY(0deg) scale(1);? ? ? ? ? top:0; ? ? ? ? left: 0; ? ? ? ? width: 640rpx; ? ? ? ? height: 700rpx; ? ? } } ? ? @keyframes flipintoright { ? ? from { transform: rotateY(90deg) scale(.9); } ? ? to { transform: rotateY(0); } }
當(dāng)時(shí)9個(gè)牌子,我用js創(chuàng)建數(shù)組存儲(chǔ)x/y和按鈕是否點(diǎn)擊(動(dòng)了點(diǎn)小腦袋)
const widthFa = 639; const heightFa = 639; const widthChil = 203; const heightChil = 203; ? position: [ ? ? ? { x: '0rpx', y: '0rpx', btn: true }, ? ? ? { x: `${widthChil + 15 ?}rpx`, y: '0rpx', btn: true }, ? ? ? { x: `${widthFa - widthChil ?}rpx`, y: '0rpx', btn: true }, ? ? ? { x: '0rpx', y: `${widthChil + 15 ?}rpx`, btn: true }, ? ? ? { x: `${widthChil + 15 ?}rpx`, y: `${widthChil + 15 ?}rpx`, btn: true }, ? ? ? { x: `${widthFa - widthChil ?}rpx`, y: `${widthChil + 15 ?}rpx`, btn: true }, ? ? ? { x: '0rpx', y: `${widthFa - widthChil ?}rpx`, btn: true }, ? ? ? { x: `${widthChil + 15 ?}rpx`, y: `${widthFa - widthChil ?}rpx`, btn: true }, ? ? ? { x: `${widthFa - widthChil ?}rpx`, y: `${widthFa - widthChil ?}rpx`, btn: true }, ? ? ],
最后,點(diǎn)擊的時(shí)候
flipArr[index] = !flipArr[index]; ? ? ? ? that.setData({ ? ? ?flipArr, ? ? ? ? ? ? ? ?isFlip: false });
就可以實(shí)現(xiàn)翻轉(zhuǎn)動(dòng)畫啦。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript之RegExp_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
正則表達(dá)式是一種用來(lái)匹配字符串的強(qiáng)有力的武器。它的設(shè)計(jì)思想是用一種描述性的語(yǔ)言來(lái)給字符串定義一個(gè)規(guī)則,凡是符合規(guī)則的字符串,我們就認(rèn)為它“匹配”了,否則,該字符串就是不合法的2017-06-06JavaScript樹形數(shù)據(jù)結(jié)構(gòu)處理
這篇文章主要介紹了JavaScript樹形數(shù)據(jù)結(jié)構(gòu)處理,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-07-07JavaScript實(shí)現(xiàn)簡(jiǎn)單貪吃蛇效果
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡(jiǎn)單貪吃蛇效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03javascript開(kāi)發(fā)實(shí)現(xiàn)貪吃蛇游戲
這篇文章主要為大家詳細(xì)介紹了javascript開(kāi)發(fā)實(shí)現(xiàn)貪吃蛇游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07JavaScript實(shí)現(xiàn)復(fù)制功能各瀏覽器支持情況實(shí)測(cè)
這兩天在做Web前端時(shí),遇到需求通過(guò)js實(shí)現(xiàn)文本復(fù)制的功能,下面與大家分享下各瀏覽器對(duì)復(fù)制功能的支持情況,感興趣的朋友可以參考下哈2013-07-07『JavaScript』限制Input只能輸入數(shù)字實(shí)現(xiàn)思路及代碼
一個(gè)文字方塊必須限制只能輸入數(shù)字(或是小數(shù)點(diǎn))并且要支援 IE 和 Firefox,接下來(lái)為大家介紹下如何解決這個(gè)需求2013-04-04js實(shí)現(xiàn)飛機(jī)大戰(zhàn)小游戲
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)飛機(jī)大戰(zhàn)小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08