[vue3+js]实现3d旋转效果

server/2024/9/23 18:07:20/
1. 实现效果图:

2.实现代码:

css:

<style lang="scss" scoped>.bottomContainer{width: 1200px;height: 400px;display: flex;justify-content: center;position: relative;margin:200px auto;align-items: center;// background-image: url("@/assets/image/test/rote_center_bg.png");background-size: 100% 100%;background-repeat: no-repeat;background-position: center;.bottomboxtest{position: absolute;width: 1000px;height: 1000px;background:radial-gradient(rgba(181, 214, 243, 0.5) 30%, rgb(108, 165, 230) 80%);left: 50%;margin-left: -500px;transform: rotateX(90deg);margin-top: -300px;border-radius: 50%;}.arrow-img {position: absolute;width: 22px;height: 22px;// top: calc(50% + 60px);top:calc(50% - 66px);cursor: pointer;z-index: 10;&.left {left: 40px;}&.right {right: 40px;}}.device-list-container{// position: absolute;display: flex;transform-style: preserve-3d;// transform: rotateX(-20deg);transform: rotateX(-10deg);width: 940px;height: 200px;.device-list {position: absolute;transform-origin: center center;transform-style: preserve-3d;transform: rotateY(-8deg);transition: all .8s;// margin-top: 75px;width: 940px;height: 400px;// left: 10%;left: -10px;display: flex;justify-content:center;.device-item {position: absolute;font-size: 16px;color: #FFFFFF;text-align: center;margin-top: 10px;.iconBox{width: 80px;height: 80px;margin:0 auto;// background: radial-gradient( circle, #E2F1FF,#A8D4FD);background: #A8D4FD;border-radius: 50%;border: 2px solid #E5F2FF;text-align: center;line-height: 80px;.roateIcon{color:#58A0F5;font-size: 32px;}}.groupName {color:#2E5480;font-size: 16px;margin-top:8px;}}}    }}
</style>

html:

<div class="bottomContainer"><div class="device-list-container"><div class="device-list" ref="deviceListRef"><div class="device-item" v-for="(item,index) in roteList"><div class="iconBox">test<!-- <i class="iconfont icon-baojing roateIcon"></i> --></div><p class="groupName">test</p></div><div class="bottomboxtest"></div></div></div><img class="arrow-img left" src="@/assets/image/test/arrow-left.png" @click="rotate(true)" alt=""><img class="arrow-img right" src="@/assets/image/test/arrow-right.png" @click="rotate(false)" alt=""></div>

js:

<script setup lang="ts">const roteList= ref([{},{},{},{},{},{}]);const deviceListRef = ref<HTMLDivElement>();const imgList = ref<NodeListOf<Element>>();let timer: NodeJS.Timer;let timeout: NodeJS.Timeout;let current = 2;let angle = 360 / 4;let rotateDeg = 1 ;const previewCount = roteList.value!.length;onMounted(async () => {rotate(true);})function rotate(isPlus: boolean) {imgList.value = imgList.value ?? deviceListRef.value!.querySelectorAll('.device-item');const SIZE = imgList.value!.length;current += isPlus ? 1 : -1;current = (current + SIZE) % SIZE;const index = getDisplayCard(current, Math.ceil(previewCount/2), SIZE);angle = 360/SIZE;rotateDeg -= angle * (isPlus ? 1 : -1);deviceListRef.value!.style.transform = `rotateY(${rotateDeg}deg)`;// deviceListRef.value!.style.transform = `rotateY(${rotateDeg}deg)`;imgList.value!.forEach((v: any, i: number) => {(v as HTMLDivElement).style.opacity = '0';if (index.includes(i)) {(v as HTMLDivElement).style.opacity = '1';}(v as HTMLDivElement).style.transform = `rotateY(${(i - 2) * angle}deg) translateZ(370px)`;})function getDisplayCard(current: number, num: number, size: number) {const offset = Math.trunc(num / 2);const res = [current];for (let i = 1; i <= offset; i++) {const pos1 = current + i;const pos2 = current - i < 0 ? current - i + size : current - i;res.push(pos1, pos2);}return res.map(v => v % size);}
}
</script>


http://www.ppmy.cn/server/54108.html

相关文章

Day50

Spring AOP 概念 AOP全称为Aspect Oriented Programming&#xff0c;表示面向切面编程。切面指的是将那些与业务无关&#xff0c;但业务模块都需要使用的功能封装起来的技术。 AOP基本术语 **连接点&#xff08;Joinpoint&#xff09;&#xff1a;**连接点就是被拦截到的程序执…

Linux修炼之路之进程概念,fork函数,进程状态

目录 一&#xff1a;进程概念 二&#xff1a;Linux中的进程概念 三&#xff1a;用getpid(),getppid()获取该进程的PID,PPID 四&#xff1a;用fork()来创建子进程 五&#xff1a;操作系统学科的进程状态 六&#xff1a;Linux中的进程状态 接下来的日子会顺顺利利&#xf…

Linux系统中交叉编译opencv库

目标&#xff1a;将opencv进行交叉编译&#xff0c;使其能在rk3326板子上运行使用。 环境&#xff1a; ubuntu&#xff1a;18.04 opencv:4.5.4 opencv源码从挂网下载&#xff1a;opencv源码下载地址 交叉编译链&#xff1a;gcc-arm-10.3-linux-gun 一.环境准备 1.交叉编译链我…

java入门-基础语法(运算符)

运算符是对变量、字面量进行运算的 符号 &#xff08;一&#xff09;基本的算术运算符、符号做连接符 &#xff08;1&#xff09;基本运算符&#xff1a;(加)&#xff0c; - &#xff08;减&#xff09;、 * &#xff08;乘&#xff09;、 / &#xff08;除&#xff09;、%&…

Linux服务器集群搭建

Linux服务器搭建 配置网络和主机名 查看虚拟机虚拟网卡ip信息 在NAT设置中查看网关地址 具体的ip根据网关网段设置 设置root账户密码&#xff0c;越简单越好 修改网卡信息 修改网卡配置&#xff0c;改成静态ip的方式 修改ip为静态方式 修改过后重启网卡服务 关闭防火墙…

MobPush REST API的推送 API之批量推送

调用验证 详情参见 REST API 概述的 鉴权方式 说明。 频率控制 详情参见推送限制策略的 接口限制 说明。 调用地址 POST http://api.push.mob.com/v3/push/createMulti 推送对象 以 JSON 格式表达&#xff0c;表示一条推送相关的所有信息 字段类型必须说明pushWorkobje…

SQL小白超详细入门教程

SQL入门教程 一、SQL概述 SQL&#xff08;Structured Query Language&#xff09;是一种用于操作关系数据库&#xff08;如MySQL、Oracle、SQL Server等&#xff09;的编程语言。它是一门ANSI&#xff08;美国国家标准化组织&#xff09;的标准计算机语言&#xff0c;用于访问…

android.bp 静态库 依赖 动态库

在Android平台上&#xff0c;使用Android.bp文件来定义和构建Android静态库&#xff08;.so文件&#xff09;和动态库&#xff08;.so文件&#xff09;之间的依赖关系是很常见的。以下是一个简单的例子&#xff0c;展示了如何在Android.bp文件中定义一个静态库&#xff0c;它依…