首页 > 其他分享 >uniapp 使用 uni.createAnimation 旋转动画模拟抽奖

uniapp 使用 uni.createAnimation 旋转动画模拟抽奖

时间:2022-12-23 09:33:18浏览次数:54  
标签:uniapp 300rpx createAnimation animationData result uni lastResult deg

效果图如下:

 用到的图片如下:

 

      wheel.png           point.png

api文档:https://uniapp.dcloud.net.cn/api/ui/animation.html#createanimation

 代码如下:

<template>
    <view>
        <view class="box">
            <image src="/static/wheel.png" :animation="animationData"></image>
            <image src="/static/point.png" @click="run"></image>
        </view>
        <view >index:{{result}} -- {{todoList[result]}}</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                animationData: {},
                lastResult: 0,
                result: 0,
                deg: 0,
                todoList: ["跑步", "游泳", "学习", "读书", "工作", "休息"],
            }
        },
        methods: {
            run() {
                let animation = uni.createAnimation({
                    transformOrigin: "50% 50%",
                    duration: 2000,
                    timingFunction: "ease",
                    delay: 0
                });
                this.animationData = animation;
                this.animationData.rotate(this.randomNum()).step();
                this.animationData = this.animationData.export();
            },
            randomNum() {
                this.result = Math.floor(Math.random() * 6); //数组索引:[0,5]
                if (this.result > this.lastResult) {
                    this.deg += 360 * 3 + (this.result - this.lastResult) * 60;
                } else {
                    this.deg += 360 * 3 + 360 - (this.lastResult - this.result) * 60;
                }
                console.log(`result:${this.result},deg:${this.deg}`);
                this.lastResult = this.result;

                return this.deg;
            },
        }
    }
</script>

<style>
    .box {
        width: 300rpx;
        height: 300rpx;
        margin: auto;
        position: relative;
    }

    image {
        position: absolute;
        width: 300rpx;
        height: 300rpx;
    }
</style>

 

标签:uniapp,300rpx,createAnimation,animationData,result,uni,lastResult,deg
From: https://www.cnblogs.com/sunshine233/p/16999994.html

相关文章

  • dos2unix命令详解
    dos2unix是将Windows格式文件转换为Unix、Linux格式的实用命令。Windows格式文件的换行符为\r\n,而Unix&Linux文件的换行符为\n.dos2unix命令其实就是将文件中的\r\n转......
  • 【Unity】基于波函数坍塌算法实现赛道自动化生成
    前言:很久没有写博客了,最近忙里偷闲准备恢复写博客的习惯,一是整理之前的笔记,二是梳理下知识点以供回顾。想写的内容很多,准备先针对以往做过的项目写个总结,最近在网上看到利......
  • 17.JUnit
    介绍优势创建方式代码文件放到src/main中测试文件放到src/test中,运行成功出现true或false断言与注解......
  • 《Unix编程艺术》
    1. 不懂Unix的人注定最终还要重复发明一个蹩脚的Unix。2. 以太网的发明者曾经说过:如果将来有什么技术来取代以太网,那么这个取代物的名字还会叫“以太网”,因为以太网是永远......
  • uniapp富文本的使用
    <editorclass="richInputContent"id="editor"@input="getEditorContent"@ready="onEditorReady"v-model="html"></editor>methods:{//初始化富文本编......
  • uniapp自定义picker城市多级联动组件
    支持多端——h5、app、微信小程序、支付宝小程序...支持自定义配置picker插件级数支持无限级注意事项:插件传入数据格式为children树形格式,内部包含:id、name参数......
  • 如何在Arch Linux 上安装 Unity 7.6 桌面?
    UnityDesktop是由Canonical构建的经典桌面环境,它从2010年到2017年是Ubuntu的一部分,但为了支持GNOME而放弃。我们认为它永远被杀死了。但它卷土重来。今年早些时......
  • Unity开发Android踩坑记
    最近在用Unity开发一个小游戏,游戏中需要打开手机相册选择图片上传作为头像。由于时间紧,随便看了一下Unity文档,然后网上搜索类似的东西。基本方法就是使用Unity去调用Ja......
  • 《Unix/Linux系统编程》教材测试
     ......
  • Unity中尝试实现3D魔方
    前言:这期demo有点失败需求:想了很久,以前都没时间做,就是在Unity中实现3D魔方,主要逻辑放在玩家操作逻辑上。思路:整个demo由model和ctrler两个脚本组成。通过玩家点击获取方......