微信小程序實現(xiàn)九宮格翻牌動畫
本文實例為大家分享了微信小程序實現(xiàn)九宮格翻牌的具體代碼,供大家參考,具體內容如下
9宮格翻牌需求:
1.進來時平鋪9個格子顯示
2.點擊開始抽獎時洗牌動作
3.洗完牌后呈現(xiàn)9個都是未翻牌的狀態(tài)
4.點擊任意一個牌子,有翻轉的動作
5.翻轉結束后出現(xiàn)中獎的彈窗
555,當時真的一點一點調動畫
敲黑板~
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 屬性定義當元素不面向屏幕時是否可見*/ ? ? 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); } }
當時9個牌子,我用js創(chuàng)建數組存儲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)翻轉動畫啦。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JavaScript之RegExp_動力節(jié)點Java學院整理
正則表達式是一種用來匹配字符串的強有力的武器。它的設計思想是用一種描述性的語言來給字符串定義一個規(guī)則,凡是符合規(guī)則的字符串,我們就認為它“匹配”了,否則,該字符串就是不合法的2017-06-06JavaScript實現(xiàn)復制功能各瀏覽器支持情況實測
這兩天在做Web前端時,遇到需求通過js實現(xiàn)文本復制的功能,下面與大家分享下各瀏覽器對復制功能的支持情況,感興趣的朋友可以參考下哈2013-07-07『JavaScript』限制Input只能輸入數字實現(xiàn)思路及代碼
一個文字方塊必須限制只能輸入數字(或是小數點)并且要支援 IE 和 Firefox,接下來為大家介紹下如何解決這個需求2013-04-04