微信小程序wxss制作扭蛋机
小程序制作扭蛋机
2019-09-24 13:26:53
公司要制作活动小程序,其中有一个扭蛋机的效果实现抽奖的功能。在网上找了好久竟没有找到(不知道是不是我找代码的方式有问题)。最后还是自己做一个吧- _ - ,效果如下:
1.wxml
当然我这里没有用wx:for遍历
- <!-- 扭蛋机 -->
- <view class="egg">
- <image class="egg_ji" src="{{imgUrl}}small_program/game/game_luck_draw_nd.png" mode="widthFix"></image>
- <image class="play {{start?'go':''}}" bindtap="eggPlay" src="{{imgUrl}}small_program/game/game_luck_draw_eggplay.png" mode="widthFix"></image>
- <image class="ball ball_1 {{start?'weiyi_1':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg1.png" mode="widthFix"></image>
- <image class="ball ball_2 {{start?'weiyi_2':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg2.png" mode="widthFix"></image>
- <image class="ball ball_3 {{start?'weiyi_3':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg3.png" mode="widthFix"></image>
- <image class="ball ball_4 {{start?'weiyi_4':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg4.png" mode="widthFix"></image>
- <image class="ball ball_5 {{start?'weiyi_5':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg5.png" mode="widthFix"></image>
- <image class="ball ball_6 {{start?'weiyi_6':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg6.png" mode="widthFix"></image>
- <image class="ball ball_7 {{start?'weiyi_7':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg7.png" mode="widthFix"></image>
- <image hidden="{{qiu}}" animation="{{ani}}" class="ball ball_end" src="{{imgUrl}}small_program/game/game_luck_draw_egg7.png" mode="widthFix" ></image>
- </view>
2.wxss
这一步比较麻烦,需要调试扭蛋的位置和动画路径
- /* 扭蛋机 */
- .egg{
- width: %;
- position: absolute;
- z-index: ;
- top: 260rpx;
- }
- .egg .egg_ji{
- width: %;
- margin-left: %;
- z-index: ;
- }
- .egg .play{
- width: 80rpx;
- position: absolute;
- z-index: ;
- top: 405rpx;
- left: 275rpx;
- }
- .egg .ball{
- width: 75rpx;
- position: absolute;
- z-index: ;
- }
- .egg .ball_1{
- top: 290rpx;
- left: 300rpx;
- }
- .egg .ball_2{
- top: 295rpx;
- left: 360rpx;
- }
- .egg .ball_3{
- top: 260rpx;
- left: 240rpx;
- }
- .egg .ball_4{
- top: 260rpx;
- left: 420rpx;
- }
- .egg .ball_5{
- top: 230rpx;
- left: 280rpx;
- }
- .egg .ball_6{
- top: 230rpx;
- left: 340rpx;
- }
- .egg .ball_7{
- top: 220rpx;
- left: 390rpx;
- }
- .egg .ball_end{
- top: 410rpx;
- left: 390rpx;
- }
- .weiyi_1 {
- animation: around1 .5s linear infinite;
- }
- .weiyi_2 {
- animation: around2 .5s linear infinite;
- }
- .weiyi_3 {
- animation: around3 .5s linear infinite;
- }
- .weiyi_4 {
- animation: around4 .5s linear infinite;
- }
- .weiyi_5 {
- animation: around5 .5s linear infinite;
- }
- .weiyi_6 {
- animation: around6 .5s linear infinite;
- }
- .weiyi_7 {
- animation: around7 .5s linear infinite;
- }
- .go{
- animation: around .3s linear ;
- }
- /* 位移 */
- @keyframes around{
- % {
- -webkit-transform: rotate(-180deg)
- }
- }
- @keyframes around1 {
- % {
- -webkit-transform: translate(0rpx, 0rpx)
- }
- % {
- -webkit-transform: translate(-100rpx, -200rpx)
- }
- % {
- -webkit-transform: translate(40rpx, -280rpx)
- }
- % {
- -webkit-transform: translate(150rpx, -200rpx)
- }
- % {
- -webkit-transform: translate(150rpx, -50rpx)
- }
- % {
- -webkit-transform: translate(, )
- }
- }
- @keyframes around2 {
- % {
- -webkit-transform: translate(0rpx, 0rpx)
- }
- % {
- -webkit-transform: translate(100rpx, -200rpx)
- }
- % {
- -webkit-transform: translate(-20rpx, -280rpx)
- }
- % {
- -webkit-transform: translate(-150rpx, -200rpx)
- }
- % {
- -webkit-transform: translate(-150rpx, -50rpx)
- }
- % {
- -webkit-transform: translate(, )
- }
- }
- @keyframes around3 {
- % {
- -webkit-transform: translate(0rpx, 0rpx)
- }
- % {
- -webkit-transform: translate(180rpx, 10rpx)
- }
- % {
- -webkit-transform: translate(240rpx, -110rpx)
- }
- % {
- -webkit-transform: translate(100rpx, -240rpx)
- }
- % {
- -webkit-transform: translate(-50rpx, -130rpx)
- }
- % {
- -webkit-transform: translate(, )
- }
- }
- @keyframes around4 {
- % {
- -webkit-transform: translate(0rpx, 0rpx)
- }
- % {
- -webkit-transform: translate(-180rpx, 10rpx)
- }
- % {
- -webkit-transform: translate(-240rpx, -110rpx)
- }
- % {
- -webkit-transform: translate(-100rpx, -240rpx)
- }
- % {
- -webkit-transform: translate(50rpx, -130rpx)
- }
- % {
- -webkit-transform: translate(, )
- }
- }
- @keyframes around5 {
- % {
- -webkit-transform: translate(0rpx, 0rpx)
- }
- % {
- -webkit-transform: translate(40rpx, 70rpx)
- }
- % {
- -webkit-transform: translate(50rpx, -210rpx)
- }
- % {
- -webkit-transform: translate(-80rpx, -100rpx)
- }
- % {
- -webkit-transform: translate(190rpx, -50rpx)
- }
- % {
- -webkit-transform: translate(, )
- }
- }
- @keyframes around6 {
- % {
- -webkit-transform: translate(0rpx, 0rpx)
- }
- % {
- -webkit-transform: translate(-150rpx, -50rpx)
- }
- % {
- -webkit-transform: translate(130rpx, -140rpx)
- }
- % {
- -webkit-transform: translate(-110rpx, -180rpx)
- }
- % {
- -webkit-transform: translate(-130rpx, -20rpx)
- }
- % {
- -webkit-transform: translate(, )
- }
- }
- @keyframes around7 {
- % {
- -webkit-transform: translate(0rpx, 0rpx)
- }
- % {
- -webkit-transform: translate(80rpx, -50rpx)
- }
- % {
- -webkit-transform: translate(-180rpx, -100rpx)
- }
- % {
- -webkit-transform: translate(50rpx, -150rpx)
- }
- % {
- -webkit-transform: translate(-180rpx, -20rpx)
- }
- % {
- -webkit-transform: translate(, )
- }
- }
3.js
这一步要比css要是要简单的多,点击使动画动起来,调用api接口获取奖品就可以了
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl: app.data.imgUrl,
- start : false,
- qiu: true,
- },
- /**
- * 点击扭蛋机
- */
- eggPlay(){
- let _this = this;
- _this.setData({
- start: true,
- })
- setTimeout(() => {
- _this.setData({
- start: false,
- qiu: false,
- })
- //球落下动画
- var animation = wx.createAnimation({
- duration: ,
- timingFunction: 'ease',
- });
- animation.opacity().step()
- this.setData({
- ani: animation.export()
- })
- }, );
- _this.setData({
- qiu: true
- })
- //将动画返回到开始位置
- var animation = wx.createAnimation({
- duration: ,
- timingFunction: 'ease',
- });
- animation.opacity().step()
- this.setData({
- ani: animation.export()
- })
- },
这个动画有个小的bug,就是连续点击按钮动画时间会变快,如果有更好的方法可以留言交流。
微信小程序wxss制作扭蛋机的更多相关文章
- 微信小程序----wxss设置样式
一.wxml 界面结构wxmL比较容易理解,主要是由八大类基础组件构成: 一.视图容器(View Container): 二.基础内容(Basic Content) 组件名 说明 组件名 说明 vie ...
- 微信小程序wxss设置样式
微信小程序wxss设置样式 对于以前搞客户端开发的来说,有着客户端的逻辑,就是不知道怎么设置样式,把对应的控件显示出来 一.wxml 界面结构wxmL比较容易理解,主要是由八大类基础组件构成: 一.视 ...
- 微信小程序在线制作 自己制作微信小程序
小程序是个什么东西?怎么自己制作微信小程序?微信小程序在线制作难吗?最近老是听这类问题,耳朵都长茧子了. 百牛信息技术bainiu.ltd整理发布于博客园 接下来作为一个技术人员的角度就为大家分析一下 ...
- 微信小程序wxss样式详解
一.wxml 界面结构wxmL比较容易理解,主要是由八大类基础组件构成: 一.视图容器(View Container): 二.基础内容(Basic Content) 组件名 说明 组件名 说明 vie ...
- 微信小程序swiper制作内容高度不定的tab选项卡
微信小程序利用swiper制作内容高度不定的tab选项卡,不使用absolute定位,不定高度,由内容自由撑开主要思路是获取内容区的高度来给swiper动态设置值 .wxml <view cla ...
- 微信小程序-从零开始制作一个跑步微信小程序
来源:伯乐在线 - 王小树 链接:http://ios.jobbole.com/90603/ 点击 → 申请加入伯乐在线专栏作者 一.准备工作 1.注册一个小程序账号,得用一个没注册过公众号的邮箱注册 ...
- 微信小程序,制作属于自己的Icon图标
前言 最近在接手一个微信小程序,发现里面的图标都是使用的image组件,看起来非常别扭,加载也不太顺畅. 就想着看看微信有没有类似自带的图标库可以使用. 有是有,就是太少了,翻来翻去好像也就 8 种, ...
- 微信小程序-WXSS
WXSS(WeiXin Style Sheets)是一套样式语言,用于描述 WXML 的组件样式. WXSS 用来决定 WXML 的组件应该怎么显示. 为了适应广大的前端开发者,我们的 WXSS 具有 ...
- less文件编译成微信小程序wxss文件
2016年9月21日,微信小程序正式开启内测.在微信生态下,触手可及.用完即走的微信小程序引起广泛关注,刷爆朋友圈子.在这样的火爆氛围中,作为一个前端开发者的我,也悄悄地去尝鲜.在做demo小示例的过 ...
随机推荐
- 跳转控制语句continue
1 continue的使用场景: 1.1 在循环语句中 注意:离开使用场景的存在是没有意义的 2 continue的作用: 2.1 单层循环对比break,然后总结两者的区别 2.1.1 break ...
- luogu P1068 分数线划定 x
P1068 分数线划定 题目描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,A 市对 所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试.面试分数线根 据 ...
- RedisTemplate访问Redis数据结构(四)——Set
Redis的Set是string类型的无序集合.集合成员是唯一的,这就意味着集合中不能出现重复的数据,Redis 中 集合是通过哈希表实现的,所以添加,删除,查找的复杂度都是O(1). SetOper ...
- [CF1082G]Petya and Graph:最小割
分析 发这篇博客的目的就是要让你们知道博主到底有多菜. 类似于[NOI2006]最大获利.(明明就是一模一样好吧!) 不知道怎么了,半秒就想到用网络流,却没想出怎么建图. 连这么简单的题都没做出来,我 ...
- [BZOJ2225][SPOJ2371]LIS2 - Another Longest Increasing Subsequence Problem:CDQ分治+树状数组+DP
分析 这回试了一下三级标题,不知道效果怎么样? 回到正题,二维最长上升子序列......嗯,我会树套树. 考虑\(CDQ\)分治,算法流程: 先递归进入左子区间. 将左,右子区间按\(x\)排序. 归 ...
- Swift equality
最后更新: 2017-07-23 在程序开发中,我们时常需要来判断两个对象是否相等.在编程思想中,两个对象相等指的是在内存中的地址相同,也就是两个指针指向同一个地址.但是在日常理解中,只要两个对象的内 ...
- [CSP-S模拟测试]:模板(ac)(线段树启发式合并)
题目描述 辣鸡$ljh\ NOI$之后就退役了,然后就滚去学文化课了.他每天都被$katarina$大神虐,仗着自己学过一些姿势就给$katarina$大神出了一道题.有一棵$n$个节点的以$1$号节 ...
- 关于c++ error : passing " "as" " discards qualifiers
http://www.cppblog.com/cppblogs/archive/2012/09/06/189749.html 今天写了一段小代码,本以为正确,但运行后,就somehow ”discar ...
- idea中svn代码冲突
1.鼠标右键点击项目根目录 --> 2.选择 subversion --> 3.resolve Text Confict --> 4.merge 手动编辑冲突部分,解决后就能正常提交 ...
- SourceTree跳过初始设置
转载https://www.cnblogs.com/xiofee/p/sourcetree_pass_initialization_setup.html 如何跳过初始设置,只需要在安装路径中添加一个a ...