3D立体卡片动效(附源码)

3D立体卡片动效

效果展示


思路分析

需求含有立体 这种关键词,我们第一反应是采用动画中的平移倾斜 等实现。如果是立体 ,必然产生阴影,应用的处理采用滤镜处理。

页面布局

html 复制代码
<div class="container">
	<div class="card">
		<div class="img_box">
			<img class="avatar" src="./img/1.jpg" alt="">
			<h3 class="name">卫庄</h3>
		</div>
		<div class="content">
			<p>韩国人,鬼谷派横剑术传人,现任"鬼谷先生,""剑圣"盖聂的师弟。"流沙"组织的创立者之一,曾任韩国大将军,韩国灭亡后统领"流沙"暗中对抗秦国和罗网组织,在他的经营下,流沙成为了令天下人闻风丧胆的职业刺客团。</p>
		</div>
	</div>
	<div class="card">此处省略相同布局</div>
	<div class="card">此处省略相同布局</div>
</div>

1. 基础样式

css 复制代码
* {
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #f3f3f3;
  overflow: hidden;
}

.container{
  position: relative;
  width: 1050px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .card {
    position: relative;
    width: 300px;
    height: 400px;
    background: #fff;
    transition: 0.5s;
    .img_box {
      position: relative;
      width: 300px;
      height: 200px;
      background-color: #00c7ff;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      .name {
        position: relative;
        color: #ffffff;
        margin-top: 10px;
      }

      .avatar {
        max-width: 100px;
      }
    }

    .content {
      box-sizing: border-box;
      position: relative;
      width: 100%;
      height: 200px;
      padding: 20px;
      color: #777;
      background: #ffffff;

      .desc{
        text-indent: 2rem;
        font-size: 15px;
        line-height: 24px;
      }
    }
  }
}

2. 实现3D效果

2.1 顶面布局

css 复制代码
card::before {
  content: "";
  position: absolute;
  top: -15px;
  left: 0;
  width: 100%;
  height: 15px;
  background-color: #00c0f6;
  transform-origin: bottom;
  transform: skewX(45deg);
  transition: 0.5s;
}

特别注意

  • 为了实现 3D效果 ,我们可以采用 伪元素 的方式。
  • card::before 用于制作卡片的 顶部切面
  • transform-origin: bottom; 用于改变元素的 基点位置
  • transform: skewX(45deg); 用于定义沿着 X 轴的 2D 倾斜转换;
  • 其中 top值height值 要结合倾斜角度计算,或者通过控制台手动微调;

2.2 侧面布局

css 复制代码
card::after {
  content: "";
  position: absolute;
  top: -15px;
  left: -15px;
  width: 15px;
  height: 50%;
  background-color: #00c0f6;
  transform-origin: left;
  transform: skewY(45deg);
  transition: 0.5s;
  border-bottom: 200px solid #d9d9d9;
}

特别注意

  • 同上
  • 思考:height:50%; 是怎么计算出来的;

组合效果


3. 阴影效果

css 复制代码
.content::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 400px;
  background: linear-gradient(transparent, transparent, rgba(0, 0, 0, 0.1));
  transform-origin: bottom;
  transform: skewX(45deg);
  transition: 0.5s;
  pointer-events: none;
  z-index: -1;
}

4. 鼠标移入效果

css 复制代码
.card:hover {
  transform: translateY(-40px);

  .content {
    &::before {
      transform: translateY(40px) skewX(45deg);
      filter: blur(5px);
      opacity: 0.5;
    }
  }
}

5. 细节补充

css 复制代码
.card:nth-child(1) {
  z-index: 3;
}

.card:nth-child(2) {
  z-index: 2;
}

.card:nth-child(3) {
  z-index: 1;
}

此处,处理定义的 层级问题 ,是为了处理 阴影的遮挡问题


温馨提示

  • 更多博文,请关注:xssy5431 小拾岁月,回复 "3D" ,获取源码;
相关推荐
叁分之一1 小时前
“我打包又失败了”
前端·npm
tang游戏王1231 小时前
AJAX进阶-day4
前端·javascript·ajax
无语听梧桐1 小时前
vue3中使用Antv G6渲染树形结构并支持节点增删改
前端·vue.js·antv g6
go2coding1 小时前
开源 复刻GPT-4o - Moshi;自动定位和解决软件开发中的问题;ComfyUI中使用MimicMotion;自动生成React前端代码
前端·react.js·前端框架
freesharer2 小时前
Zabbix 配置WEB监控
前端·数据库·zabbix
web前端神器2 小时前
forever启动后端服务,自带日志如何查看与设置
前端·javascript·vue.js
是Yu欸2 小时前
【前端实现】在父组件中调用公共子组件:注意事项&逻辑示例 + 将后端数组数据格式转换为前端对象数组形式 + 增加和删除行
前端·vue.js·笔记·ui·vue
weixin_505154462 小时前
组件丰富、支持2/3D数据可视化的编辑器平台软件?
3d·信息可视化·编辑器·数字孪生·3d产品配置器·产品交互展示·3d交互设计工具
今天是 几 号2 小时前
WEB攻防-XSS跨站&反射型&存储型&DOM型&标签闭合&输入输出&JS代码解析
前端·javascript·xss
A-超2 小时前
html5 video去除边框
前端·html·html5