在微信开发者工具中设计一个抽奖转盘程序,显示为动态效果请为我生成需要的代码,包括.js ..json .wxml .wxss,如果代码过长,请分段生成
时间: 2024-02-19 20:58:23 浏览: 225
抽奖转转盘-微信小程序-源代码
5星 · 资源好评率100%
好的,我可以为您提供一个简单的抽奖转盘程序的代码,代码如下:
.wxml文件代码:
```
<view class="container">
<view class="turntable">
<image src="{{turntableBg}}" class="turntable-bg"></image>
<view class="turntable-btn" bindtap="startLottery">
<image src="{{btnImg}}" class="btn"></image>
</view>
<view class="prize-list">
<view class="prize-item">{{prizeList[0]}}</view>
<view class="prize-item">{{prizeList[1]}}</view>
<view class="prize-item">{{prizeList[2]}}</view>
<view class="prize-item">{{prizeList[3]}}</view>
<view class="prize-item">{{prizeList[4]}}</view>
<view class="prize-item">{{prizeList[5]}}</view>
</view>
</view>
</view>
```
.wxss文件代码:
```
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.turntable {
position: relative;
width: 300rpx;
height: 300rpx;
margin: 20rpx;
}
.turntable-bg {
width: 100%;
height: 100%;
}
.turntable-btn {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 80rpx;
height: 80rpx;
border-radius: 50%;
background-color: #f44336;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.5);
z-index: 10;
}
.btn {
width: 60rpx;
height: 60rpx;
}
.prize-list {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(30deg);
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.prize-item {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-30deg);
width: 200rpx;
height: 200rpx;
text-align: center;
font-size: 28rpx;
color: #fff;
line-height: 200rpx;
font-weight: bold;
text-shadow: 0 0 10rpx rgba(0, 0, 0, 0.5);
}
```
.js文件代码:
```
Page({
data: {
turntableBg: '/images/turntable-bg.png',
btnImg: '/images/btn.png',
prizeList: ['一等奖', '二等奖', '三等奖', '谢谢参与', '三等奖', '二等奖']
},
startLottery() {
let prizeList = this.data.prizeList;
let index = Math.floor(Math.random() * prizeList.length);
let that = this;
// 旋转动画
let animation = wx.createAnimation({
duration: 4000,
timingFunction: 'ease-out'
});
animation.rotate(360 * 8 + (360 / prizeList.length) * (index + 0.5)).step();
this.setData({
animation: animation.export()
});
// 弹出中奖提示框
setTimeout(function() {
wx.showModal({
title: '恭喜您',
content: '获得' + prizeList[index],
showCancel: false,
success: function(res) {
if (res.confirm) {
// 清空动画
let animation = wx.createAnimation({
duration: 0,
timingFunction: 'ease-out'
});
animation.rotate(0).step();
that.setData({
animation: animation.export()
});
}
}
});
}, 4000);
}
});
```
.json文件代码:
```
{
"navigationBarTitleText": "抽奖转盘"
}
```
以上代码是一个简单的抽奖转盘程序,您可以将其复制到您的微信开发者工具中进行使用。
阅读全文