Skip to content

Instantly share code, notes, and snippets.

@mqxu
Created November 3, 2019 12:14
Show Gist options
  • Save mqxu/e3bcdfb4a44ff33ef36d90ae8eecad0a to your computer and use it in GitHub Desktop.
Save mqxu/e3bcdfb4a44ff33ef36d90ae8eecad0a to your computer and use it in GitHub Desktop.
【iCSS:行为】使用transform模拟视差滚动
<div class="bruce">
<ul class="parallax-scrolling">
<li>translateZ(-1px)</li>
<li>translateZ(-2px)</li>
<li>translateZ(-3px)</li>
</ul>
<p>内容</p>
<ul class="parallax-scrolling">
<li>translateZ(-1px)</li>
<li>translateZ(-2px)</li>
<li>translateZ(-3px)</li>
</ul>
</div>
$bg: "https://yangzw.vip/static/codepen/bg.jpg";
.bruce {
overflow: auto;
perspective: 1px;
transform-style: preserve-3d;
p {
height: 300px;
line-height: 300px;
text-align: center;
font-size: 20px;
color: #f66;
}
}
.parallax-scrolling {
display: flex;
justify-content: center;
align-items: center;
height: 1000px;
background: url($bg) no-repeat center fixed;
li {
width: 500px;
text-align: center;
font-weight: bold;
font-size: 60px;
&:nth-child(1) {
color: #f66;
transform: translateZ(-1px);
}
&:nth-child(2) {
color: #09f;
transform: translateZ(-2px);
}
&:nth-child(3) {
color: #3c9;
transform: translateZ(-3px);
}
}
}
<link href="https://yangzw.vip/static/css/reset.css" rel="stylesheet" />
<link href="https://yangzw.vip/static/css/main.css" rel="stylesheet" />
<link href="https://yangzw.vip/static/css/theme.scss" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment