Vue2实现掷色子(多个色子)

2023-11-02 15:44

本文主要是介绍Vue2实现掷色子(多个色子),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

效果图:

在这里插入图片描述

在这里插入图片描述

代码实现:

就是将每个色子独立起来,然后同时产生5个随机数,然后每个筛子取随机数对应的色子点数图片

图片文件
在这里插入图片描述

<template><div class="home" v-cloak><!-- 骰子区域 --><div class="dice"><div class="dice-box1"><div class="wraps"><div v-for="(ite,idx) in imgUrl" :key="idx" class="box" v-show="bannerIndex==idx"><img :src="ite.img"></div><div v-for="(ite,idx) in imgUrl" :key="idx" class="box" v-show="bannerIndex2==idx"><img  :src="ite.img"></div><!-- <div v-for="(ite,idx) in imgUrl" :key="idx" class="box" v-show="bannerIndex3==idx"><img  :src="ite.img"></div> --></div><div class="wraps"><div v-for="(ite,idx) in imgUrl" :key="idx" class="box" v-show="bannerIndex4==idx"><img  :src="ite.img"></div><div v-for="(ite,idx) in imgUrl" :key="idx" class="box" v-show="bannerIndex5==idx"><img  :src="ite.img"></div><div v-for="(ite,idx) in imgUrl" :key="idx" class="box" v-show="bannerIndex6==idx"><img  :src="ite.img"></div></div></div></div><!-- 摇骰子按钮 --><div class="dice-start" @click="handlestart"><span>摇骰子</span></div></div>
</template><script>export default {name: 'Home',components: {},data() {return {imgUrl: [ ],bannerIndex: 1,bannerIndex2: 3,bannerIndex3: 5,bannerIndex4: 4,bannerIndex5: 2,bannerIndex6: 0,setInter1: null, // 定时器mask: false,showNa: true, //防抖}},created(){this.imgUrl = []let arr = ['one','two','three','four','five','six']arr.forEach((item,index)=>{this.imgUrl.push({id:index+1,img: require(`./img/${item}.jpg`)})})console.log('夫斯基大街',this.imgUrl)},methods: {handlestart() { //开始this.showNa = false //防抖this.setInter1 = setInterval(() => {this.bannerIndex++this.bannerIndex2++this.bannerIndex3++this.bannerIndex4++this.bannerIndex5++this.bannerIndex6++if (this.bannerIndex == this.imgUrl.length) {this.bannerIndex = 0this.bannerIndex2 = 0this.bannerIndex3 = 0this.bannerIndex4 = 0this.bannerIndex5 = 0this.bannerIndex6 = 0}},100)setTimeout(() => {clearInterval(this.setInter1) // 先将已有的计时器清除//随机1-6点数this.bannerIndex = Math.round(Math.random() * 5);this.bannerIndex2 = Math.round(Math.random() * 5);this.bannerIndex3 = Math.round(Math.random() * 5);this.bannerIndex4 = Math.round(Math.random() * 5);this.bannerIndex5 = Math.round(Math.random() * 5);this.bannerIndex6 = Math.round(Math.random() * 5);setTimeout(() => {this.showNa = truethis.mask = true}, 300)}, 1000)},maskClose() { //关闭中奖信息this.mask = false}}}
</script><style lang="scss" scoped>* {margin: 0;padding: 0;}.home {position: relative;height: 100vh;overflow: hidden;background: #e5e5e5;background-size: cover;}[v-cloak] {display: none !important;}.dice {width: 100%;margin: 142px auto 0;.dice-box1 {display: flex;flex-direction: column;justify-content: center;align-items: center;.box {width: 5rem;height: 5rem;position: relative;&:nth-child(n+1){margin-right: 30px;}&:nth-child(n){transform: rotate(60deg);}&:nth-child(2n){transform: rotate(30deg);}&:nth-child(3n){transform: rotate(90deg);}&:nth-child(4n){transform: rotate(120deg);}&:nth-child(5n){transform: rotate(240deg);}&:nth-child(6n){transform: rotate(300deg);}img {width: 5rem;height: 5rem;border-radius: 15px;position: absolute;}}.wraps{width: 100%;display: flex;justify-content: center;&:first-child{margin-bottom: 20px;}}}}.dice-start {background: red;width: 280px;height: 72px;border: 2px solid #f9fabe;border-radius: 38px;margin: 180px auto 0;display: flex;justify-content: center;align-items: center;img {width: 42px;height: 42px;margin-right: 15px;}span {font-size: 36px;font-family: PingFang SC, PingFang SC-Regular;font-weight: bold;color: #f9fabe;letter-spacing: 0.6px;}}</style>

这篇关于Vue2实现掷色子(多个色子)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/331635

相关文章

Go语言使用select监听多个channel的示例详解

《Go语言使用select监听多个channel的示例详解》本文将聚焦Go并发中的一个强力工具,select,这篇文章将通过实际案例学习如何优雅地监听多个Channel,实现多任务处理、超时控制和非阻... 目录一、前言:为什么要使用select二、实战目标三、案例代码:监听两个任务结果和超时四、运行示例五

python使用Akshare与Streamlit实现股票估值分析教程(图文代码)

《python使用Akshare与Streamlit实现股票估值分析教程(图文代码)》入职测试中的一道题,要求:从Akshare下载某一个股票近十年的财务报表包括,资产负债表,利润表,现金流量表,保存... 目录一、前言二、核心知识点梳理1、Akshare数据获取2、Pandas数据处理3、Matplotl

分布式锁在Spring Boot应用中的实现过程

《分布式锁在SpringBoot应用中的实现过程》文章介绍在SpringBoot中通过自定义Lock注解、LockAspect切面和RedisLockUtils工具类实现分布式锁,确保多实例并发操作... 目录Lock注解LockASPect切面RedisLockUtils工具类总结在现代微服务架构中,分布

Java使用Thumbnailator库实现图片处理与压缩功能

《Java使用Thumbnailator库实现图片处理与压缩功能》Thumbnailator是高性能Java图像处理库,支持缩放、旋转、水印添加、裁剪及格式转换,提供易用API和性能优化,适合Web应... 目录1. 图片处理库Thumbnailator介绍2. 基本和指定大小图片缩放功能2.1 图片缩放的

Python使用Tenacity一行代码实现自动重试详解

《Python使用Tenacity一行代码实现自动重试详解》tenacity是一个专为Python设计的通用重试库,它的核心理念就是用简单、清晰的方式,为任何可能失败的操作添加重试能力,下面我们就来看... 目录一切始于一个简单的 API 调用Tenacity 入门:一行代码实现优雅重试精细控制:让重试按我

Redis客户端连接机制的实现方案

《Redis客户端连接机制的实现方案》本文主要介绍了Redis客户端连接机制的实现方案,包括事件驱动模型、非阻塞I/O处理、连接池应用及配置优化,具有一定的参考价值,感兴趣的可以了解一下... 目录1. Redis连接模型概述2. 连接建立过程详解2.1 连php接初始化流程2.2 关键配置参数3. 最大连

Python实现网格交易策略的过程

《Python实现网格交易策略的过程》本文讲解Python网格交易策略,利用ccxt获取加密货币数据及backtrader回测,通过设定网格节点,低买高卖获利,适合震荡行情,下面跟我一起看看我们的第一... 网格交易是一种经典的量化交易策略,其核心思想是在价格上下预设多个“网格”,当价格触发特定网格时执行买

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统

Python对接支付宝支付之使用AliPay实现的详细操作指南

《Python对接支付宝支付之使用AliPay实现的详细操作指南》支付宝没有提供PythonSDK,但是强大的github就有提供python-alipay-sdk,封装里很多复杂操作,使用这个我们就... 目录一、引言二、准备工作2.1 支付宝开放平台入驻与应用创建2.2 密钥生成与配置2.3 安装ali

Spring Security 单点登录与自动登录机制的实现原理

《SpringSecurity单点登录与自动登录机制的实现原理》本文探讨SpringSecurity实现单点登录(SSO)与自动登录机制,涵盖JWT跨系统认证、RememberMe持久化Token... 目录一、核心概念解析1.1 单点登录(SSO)1.2 自动登录(Remember Me)二、代码分析三、