2020/9/27 0:00:00
泉源:不详
作者:未知
微信抽奖功效是小程序推广中很是适用有用功效,,,,其中样式有转盘形式,,,,也有翻牌打乱式等等其他差别的抽奖形式,,,,下面小编就微信抽奖小程序类似翻牌样式的开发流程来详细介绍
翻牌打乱活动抽奖活动,,,,或许需求是这样的,,,,九宫格卡牌,,,,先正面展示所有奖品,,,,然后卡牌翻转,,,,打乱排序,,,,点击卡牌,,,,然后抽奖。。。。。

这个需求自己着实不难,,,,主要是分为三步;;;
目录
-
1、展示所有卡牌,,,,然后翻转
-
2、打乱所有卡牌
-
3、点击其中一张卡牌,,,,抽奖
1卡牌翻转
我们先在dom中渲染9个卡牌。。。。。

-
<view class="card-module">
-
<view class="card {{showClass ? 'change' : ''}}>
-
<view class="front card-item">{{cardItem.front}}</view>
-
<view class="back card-item">{{cardItem.back}}</view>
-
</view>
-
</repeat>
-
</view>
在数据中天生模拟卡牌数据
-
cardData: [
-
{
-
animationData: {},
-
front: '正面1',
-
back: '反面1'
-
},
-
...
-
...
-
{
-
animationData: {},
-
front: '正面9',
-
back: '反面9'
-
}
-
],
-
showClass: false,
在样式中把卡牌的基本样式渲染出来
-
.card-module{
-
padding: 45rpx;
-
display: flex;
-
flex-direction: row;
-
flex-wrap: wrap;
-
transform:translate3d(0,0,0);
-
.card{
-
width: 200rpx;
-
height: 200rpx;
-
line-height: 200rpx;
-
text-align: center;
-
color: #fff;
-
margin: 10rpx;
-
position:relative;
-
overflow:hidden;
-
.card-item{
-
position:absolute;
-
left:0;
-
top:0;
-
width:100%;
-
height:100%;
-
transition:all .5s ease-in-out;
-
transform-style:preserve-3d;
-
backface-visibility:hidden;
-
box-sizing:border-box;
-
}
-
.front{
-
background-color: red;
-
transform: rotateY(0deg);
-
z-index:2;
-
}
-
.back{
-
background-color: #009fff;
-
transform: rotateY(180deg);
-
z-index:1;
-
}
-
}
-
.card.change{
-
.front{
-
z-index:1;
-
transform: rotateY(180deg);
-
}
-
.back{
-
z-index:2;
-
transform: rotateY(0deg);
-
}
-
}
-
}
这里有些css属性可能需要大部增补学习一下
css3 backface-visibility 属性
界说和用法 backface-visibility 属性界说当元素不面向屏幕时是否可见。。。。。 若是在旋转元素不希望看到其反面时,,,,该属性很有用。。。。。
CSS3 perspective 属性
perspective 属性界说 3D 元素距视图的距离,,,,以像素计。。。。。该属性允许您改变 3D 元素审查 3D 元素的视图。。。。。 当为元素界说 perspective 属性时,,,,其子元素会获得透视效果,,,,而不是元素自己。。。。。
2卡牌打乱
由于营业上是抽奖使用的,,,,以是选择的方案是:翻转后,,,,卡牌收回到中心的卡牌中心,,,,然后再让卡牌回到原来的位置。。。。。 关于小程序的原生框架有支持的动画接口,,,,若不相识的请前往: developers.weixin.qq.com/miniprogram… 在对动画有基真相识之后,,,,我们可以最先在翻转的基础上加上打乱的动画了 微信小程序的动画接口使用方式是在dom工具上面加上animation工具。。。。。 dom
-
<view class="card-module">
-
<view class="card {{showClass ? 'change' : ''}} animation="{{cardItem.animationData}}" >
-
<view class="front card-item">{{cardItem.front}}</view>
-
<view class="back card-item">{{cardItem.back}}</view>
-
</view>
-
</repeat>
-
</view>
script
-
allMove () {
-
// 110 是卡牌宽度加边距
-
this.methods.shuffle.call(this, 110)
-
let timer = setTimeout(() => {
-
clearTimeout(timer)
-
this.methods.shuffle.call(this, 0)
-
this.$apply()
-
}, 1000)
-
},
-
// 洗牌
-
shuffle (translateUnit) {
-
let curCardData = this.cardData
-
curCardData.map((item, index) => {
-
let animation = wepy.createAnimation({
-
duration: 500,
-
timingFunction: 'ease'
-
})
-
animation.export()
-
switch (index) {
-
case 0:
-
animation.translate(translateUnit, translateUnit).step()
-
break
-
case 1:
-
animation.translate(0, translateUnit).step()
-
break
-
case 2:
-
animation.translate(-translateUnit, translateUnit).step()
-
break
-
case 3:
-
animation.translate(translateUnit, 0).step()
-
break
-
case 4:
-
animation.translate(0, 0).step()
-
break
-
case 5:
-
animation.translate(-translateUnit, 0).step()
-
break
-
case 6:
-
animation.translate(translateUnit, -translateUnit).step()
-
break
-
case 7:
-
animation.translate(0, -translateUnit).step()
-
break
-
case 8:
-
animation.translate(-translateUnit, -translateUnit).step()
-
break
-
}
-
item.animationData = animation.export()
-
})
-
this.cardData = curCardData
-
this.$apply()
-
},
3卡牌翻转
dom代码
-
<view class="card-module">
-
<view class="card {{showClass ? 'change' : ''}} {{curIndex === index ? 'getprize' : ''}}" @tap="itemChage({{cardItem}}, {{index}})" animation="{{cardItem.animationData}}" >
-
<view class="front card-item">{{cardItem.front}}</view>
-
<view class="back card-item">{{cardItem.back}}</view>
-
</view>
-
</repeat>
-
</view>
script代码
-
data中界说一个curIndex = -1的工具
-
data = {
-
curOpen: -1,
-
}
-
methods = {
-
// 抽奖
-
itemChage (item, curIndex) {
-
this.cardData[curIndex].front = 'iphone x'
-
console.log(item, curIndex)
-
this.curOpen = curIndex
-
}
-
}
less
-
.card.getprize{
-
.front{
-
z-index:2;
-
transform: rotateY(0deg);
-
}
-
.back{
-
z-index:1;
-
transform: rotateY(180deg);
-
}
-
}
那我们是不是可以在卡牌中也使用二维数组结构属性
-
resetData () {
-
const total = 9 // 总数
-
const lineTotal = 3 // 单行数
-
curCardData.map((item, index) => {
-
let curCardData = this.cardData
-
let x = index % lineTotal
-
let y = parseInt(index / lineTotal)
-
item.twoArry = {x, y}
-
})
-
}
在位移动画中使用二维结构的差值举行位移
-
// 洗牌
-
shuffle (translateUnit) {
-
let curCardData = this.cardData
-
curCardData.map((item, index) => {
-
let animation = wepy.createAnimation({
-
duration: 500,
-
timingFunction: 'ease'
-
})
-
animation.export()
-
const translateUnitX = translateUnit * (1 - item.twoArry.x)
-
const translateUnitY = translateUnit * (1 - item.twoArry.y)
-
animation.translate(translateUnitX, translateUnitY).step()
-
item.animationData = animation.export()
-
})
-
this.cardData = curCardData
-
this.$apply()
-
},
这样整个动画就算完成了,,,,虽然还想相识其他抽奖样式怎样开发制作,,,,可以参考以下文章:
【本站声明】
1、本站文章中所选用的图片及文字泉源于网络以及用户投稿,,,,由于未联系到知识产权人或未发明有关知识产权的挂号,,,,若有知识产权人并不肯意我们使用,,,,若是有侵权请连忙联系。。。。。
2、本网站差池文章中所涉及的内容真实性、准确性、可靠性认真,,,,仅系客观性形貌,,,,如您需要相识该类商品/服务详细的资讯,,,,请您直接与该类商品/服务的提供者联系。。。。。
KESION pp电子软件
KESION pp电子软件是海内领先的在线教育软件及私域社交电商软件服务提供商,,,,恒久专注于为企业提供在线教育软件及社交电商SaaS平台解决方案。。。。。
公司焦点产品云开店SaaS社交电商服务平台、在线教育SaaS服务平台、教育企业数字化SaaS云平台、企微营销助手、私有化自力安排品牌网校和在线教育咨询等。。。。。KESION 一直通过手艺立异,,,,提供产品和服务,,,,助力企业向数字化转型,,,,通过科技驱动商业刷新,,,,让商业变得更智慧!