今天就跟大家聊聊有關怎么在微信小程序中實現一個圖片翻轉效果,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
頁面:
<view class='rotateCtn' bindtap='rotateFn'> <!--正面的框 --> <view class='frame {{class1}}'> <image src="{{vo.cover1}}"></image> </view> <!--背面的框 --> <view class='frame {{class2}}'> <image src="{{vo.cover2}}"></image> </view> </view>
代碼:
data: { class1: 'z1', //默認正面在上面 class2: 'z2' }, rotateFn: function(e) { let data = this.data; if (data.class1 == 'z1' && data.class2 == 'z2') { this.run('front', 'back', 'z2', 'z1'); } else { this.run('back', 'front', 'z1', 'z2'); } }, run: function(a, b, c, d) { let that = this; that.setData({ class1: a, class2: b, }) setTimeout(function() { that.setData({ class1: c, class2: d, }) }, 1000); },
還有樣式:
page{position: relative;height: 100%;background-color: #F6F6F6} .rotateCtn{position: absolute;width: 70%;height: 70%;left: 15%;bottom: 20%;transform-style:preserve-3d;} .frame{position: absolute;height: 100%;width: 100%;} .frame image{height: 100%;width: 100%;border-radius: 8px;} .front{animation:front 1s linear 1;backface-visibility: hidden;} .back{animation:back 1s linear 1;} @keyframes front{from{transform: rotateY(0deg);} to{transform: rotateY(180deg);}} @keyframes back{from{transform: rotateY(-180deg);} to{transform: rotateY(0deg);}} .z1{z-index:6} .z2{z-index:5}
看完上述內容,你們對怎么在微信小程序中實現一個圖片翻轉效果有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。