滑动视差 营造高级感觉
**我们在很多页面中都见到过这种高级的滑动效果
其实原理很简单 可以用css实现很高级的感觉我们一起康康吧**
HTML部分:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>滑动视差</title>
<link rel="stylesheet" href="hdsc.css">
</head>
<body>
<div class="shell">
<div class="image" style="background-image: url('imgs/1.jpg');"></div>
<div class="heading">
<h1>因为想和你一起</h1>
</div>
<div class="text">
<h1>这小高级感挠一下就上来了</h1>
</div>
<div class="image" style="background-image: url('imgs/2.jpg');"></div>
<div class="heading">
<h1>因为想和你一起</h1>
</div>
<div class="text">
<h1>因为想和你一起</h1>
</div>
<div class="image" style="background-image: url('imgs/3.jpg');"></div>
<div class="heading">
<h1>因为想和你一起</h1>
</div>
<div class="text">
<h1>因为想和你一起</h1>
</div>
<div class="image" style="background-image: url('imgs/4.jpg');"></div>
<div class="heading">
<h1>和我一起</h1>
</div>
</div>
</body>
</html>
CSS部分:
* {
padding: 0;
margin: 0;
}
.shell{
height: 100vh;
overflow-x: hidden;
perspective: 3px;
}
.shell div{
position: relative;
display: flex;
justify-content: center;
align-items: center;
font-size: 30px;
letter-spacing: 2px;
}
.image{
transform: translateZ(-1px) scale(1.6);
background-size: cover;
height: 100vh;
z-index: -1;
}
.text{
height: 50vh;
background-color: #fff;
}
.text h1{
color: #000;
}
.heading{
z-index: -1;
transform: translateY(-30vh) translateZ(1px);
color: #fff;
font-size: 30px;
}
![效果出来了](https://img-blog.csdnimg.cn/fcda5e4c8d204e7e8cd4b52f9d50a871.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQ2hlbk5hblhT,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)