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

相关文章

springboot filter实现请求响应全链路拦截

《springbootfilter实现请求响应全链路拦截》这篇文章主要为大家详细介绍了SpringBoot如何结合Filter同时拦截请求和响应,从而实现​​日志采集自动化,感兴趣的小伙伴可以跟随小... 目录一、为什么你需要这个过滤器?​​​二、核心实现:一个Filter搞定双向数据流​​​​三、完整代码

SpringBoot利用@Validated注解优雅实现参数校验

《SpringBoot利用@Validated注解优雅实现参数校验》在开发Web应用时,用户输入的合法性校验是保障系统稳定性的基础,​SpringBoot的@Validated注解提供了一种更优雅的解... 目录​一、为什么需要参数校验二、Validated 的核心用法​1. 基础校验2. php分组校验3

Python实现AVIF图片与其他图片格式间的批量转换

《Python实现AVIF图片与其他图片格式间的批量转换》这篇文章主要为大家详细介绍了如何使用Pillow库实现AVIF与其他格式的相互转换,即将AVIF转换为常见的格式,比如JPG或PNG,需要的小... 目录环境配置1.将单个 AVIF 图片转换为 JPG 和 PNG2.批量转换目录下所有 AVIF 图

Pydantic中model_validator的实现

《Pydantic中model_validator的实现》本文主要介绍了Pydantic中model_validator的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录引言基础知识创建 Pydantic 模型使用 model_validator 装饰器高级用法mo

Vue3使用router,params传参为空问题

《Vue3使用router,params传参为空问题》:本文主要介绍Vue3使用router,params传参为空问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录vue3使用China编程router,params传参为空1.使用query方式传参2.使用 Histo

AJAX请求上传下载进度监控实现方式

《AJAX请求上传下载进度监控实现方式》在日常Web开发中,AJAX(AsynchronousJavaScriptandXML)被广泛用于异步请求数据,而无需刷新整个页面,:本文主要介绍AJAX请... 目录1. 前言2. 基于XMLHttpRequest的进度监控2.1 基础版文件上传监控2.2 增强版多

Redis分片集群的实现

《Redis分片集群的实现》Redis分片集群是一种将Redis数据库分散到多个节点上的方式,以提供更高的性能和可伸缩性,本文主要介绍了Redis分片集群的实现,具有一定的参考价值,感兴趣的可以了解一... 目录1. Redis Cluster的核心概念哈希槽(Hash Slots)主从复制与故障转移2.

springboot+dubbo实现时间轮算法

《springboot+dubbo实现时间轮算法》时间轮是一种高效利用线程资源进行批量化调度的算法,本文主要介绍了springboot+dubbo实现时间轮算法,文中通过示例代码介绍的非常详细,对大家... 目录前言一、参数说明二、具体实现1、HashedwheelTimer2、createWheel3、n

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.

Mybatis 传参与排序模糊查询功能实现

《Mybatis传参与排序模糊查询功能实现》:本文主要介绍Mybatis传参与排序模糊查询功能实现,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、#{ }和${ }传参的区别二、排序三、like查询四、数据库连接池五、mysql 开发企业规范一、#{ }和${ }传参的