微信小程序?qū)崿F(xiàn)九宮格翻牌動畫
本文實例為大家分享了微信小程序?qū)崿F(xiàn)九宮格翻牌的具體代碼,供大家參考,具體內(nèi)容如下

9宮格翻牌需求:
1.進(jìn)來時平鋪9個格子顯示
2.點擊開始抽獎時洗牌動作
3.洗完牌后呈現(xiàn)9個都是未翻牌的狀態(tài)
4.點擊任意一個牌子,有翻轉(zhuǎn)的動作
5.翻轉(zhuǎn)結(jié)束后出現(xiàn)中獎的彈窗
555,當(dāng)時真的一點一點調(diào)動畫
敲黑板~
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: 動畫基本上我是用添加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;
}
?
?
?
// 翻牌動畫
.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)元素不面向屏幕時是否可見*/
? ? 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)時9個牌子,我用js創(chuàng)建數(shù)組存儲x/y和按鈕是否點擊(動了點小腦袋)
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 },
? ? ],最后,點擊的時候
flipArr[index] = !flipArr[index]; ? ? ?
?
that.setData({
? ? ?flipArr, ? ? ? ? ?
? ? ?isFlip: false
});就可以實現(xiàn)翻轉(zhuǎn)動畫啦。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
單行 JS 實現(xiàn)移動端金錢格式的輸入規(guī)則
這篇文章主要介紹了單行 JS 實現(xiàn)移動端金錢格式的輸入規(guī)則,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-05-05
JavaScript實現(xiàn)手寫原生任務(wù)定時器
定時器顧名思義就是在某個特定的時間去執(zhí)行一些任務(wù),現(xiàn)代的應(yīng)用程序早已不是以前的那些由簡單的增刪改查拼湊而成的程序了,高復(fù)雜性早已是標(biāo)配,而任務(wù)的定時調(diào)度與執(zhí)行也是對程序的基本要求了。本文將利用JavaScript手寫原生任務(wù)定時器,需要的可以參考一下2022-03-03

