当前位置: 首页 > 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;}}}
}

相关文章:

  • 稍早版本的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日(平滑)
  • 长沙天心阁举办古琴音乐会:文旅向深,让游客听见城市的底蕴
  • 中国医药科技出版社回应发布“男性患子宫肌瘤”论文:正在核查
  • 五一档观众最满意《水饺皇后》
  • “注胶肉”或已泛滥?这几种肉,再爱吃也要管住嘴
  • 山大齐鲁医院护士论文现“男性确诊子宫肌瘤”,院方称将核实
  • 各地各部门贯彻落实习近平总书记重要指示精神坚决防范遏制重特大事故发生