当前位置: 首页 > news >正文

js实现2D图片堆叠在一起呈现为3D效果,类似大楼楼层的效果,点击每个楼层不会被其他楼层遮挡

js实现2D图片堆叠在一起呈现为3D效果,类似大楼楼层的效果,点击每个楼层不会被其他楼层遮挡。实现过程使用元素的绝对定位,通过伪元素设置背景图片和文字,效果如下:

index.jsx:

import React, { useEffect, useState } from 'react'
import styles from './style.less'export default function index() {const handleClick = (floor) => {console.log(floor);}return (<div className={styles.container}><div className={styles.floor} onClick={() => handleClick(1)}></div><div className={styles.floor} onClick={() => handleClick(2)}></div></div>)
}

style.less:

.container {position: relative;width: 200px; /* 容器宽度 */height: 400px; /* 容器高度 */
}.floor {position: absolute;cursor: pointer;&.disabled{// 阻止元素响应鼠标/指针事件,用户无法点击、悬停或与元素进行任何交互pointer-events: none;&::after{opacity: .15;}}&::before{transform: scale(0.71);content: "";display: block;transition: all .3s;pointer-events: none;position: absolute;background-repeat: no-repeat;background-position: center;background-size: cover;}&::after{display: block;position: absolute;font-style: italic;font-size: 23px;color: #ff0000;right: -146px;font-weight: 100;}&:hover{&::after{color: #ffffff;font-size: 25px;}}&:nth-child(1){bottom: 0px;&::before{width: 300px;height: 160px;background: url(~@/assets/images/1.png) no-repeat center / 100% 100%;top: -65px;left: -10px;}&::after{content: "1F";height: 36px;line-height: 36px;}&:hover{&::before{// background-image: url(/images/1f-active.png);background-color: #a5fcc8;}}}&:nth-child(2){bottom: 73px;&::before{width: 300px;height: 160px;background: url(~@/assets/images/1.png) no-repeat center / 100% 100%;top: -65px;left: -10px;}&::after{content: "2F";height: 36px;line-height: 36px;}&:hover{&::before{// background-image: url(/images/2f-active.png);background-color: #a5fcc8;}}}
}

http://www.dtcms.com/a/148761.html

相关文章:

  • 稍早版本的ICG3000使用VXLAN建立L2 VPN
  • [PTA]2025 CCCC-GPLT天梯赛 胖达的山头
  • 『不废话』之Python管理工具uv快速入门
  • uv包管理器如何安装依赖?
  • 直播分享|TinyVue 多端实战与轻量图标库分享
  • 多头注意力(Multi‑Head Attention)
  • A2A + MCP:构建实用人工智能系统的超强组合
  • rlm.exe是什么
  • vue3:十一、主页面布局(修改左侧导航条的样式)
  • vue watch监听路由,第一次进入不触发解决办法
  • CLIP | 训练过程中图像特征和文本特征的在嵌入空间中的对齐(两个投影矩阵的学习)
  • vscode本地docker gdb调试python
  • Qt-托盘的实现
  • Qt信号槽连接的三种方法对比
  • 开源QML控件:进度条滑动控件(含源码下载链接)
  • 【得物】20250419笔试算法题
  • 高级java每日一道面试题-2025年4月22日-基础篇[反射篇]-如何通过反射创建一个对象实例?
  • ProxySQL 的性能优化需结合实时监控数据与动态配置调整
  • 实验一-密码学数学基础
  • 2025年4月22日(平滑)
  • lvgl 动画设计
  • 【第九章 Python学习之函数Ⅱ】
  • 【汽车ECU电控数据管理篇】S19文件格式解析篇章
  • Java面试实战:谢飞机的求职记 - Spring Boot、Redis与微服务技术问答解析
  • RAG是什么?
  • IDEA下载kotlin-compiler-embeddable特别慢
  • 1.C++ 动态内存分配对比:malloc/free VS new/delete以及 2.nullptr VS NULL 区别
  • python环境使用conda,conda如何升级默认的python版本
  • Spring集合注入Bean
  • 从项目真实场景中理解二分算法的细节(附图解和模板)