zyx*_*sdk 3 html css css3 parallax css-transitions
是否可以使用css过渡来制作背景图像的视差效果?视差应该比滚动慢,所以需要减速 - 是否可以用css做到这一点?或者如果没有,如何使用js/jquery做到最好?
我关心最佳性能脚本,因为我的网页有点过载.
有人可以告诉或展示如何做到这一点?我将非常感激.
CSS有一个perspective属性,你可以结合使用,zoom以实现一个元素"后面"或"在"前面的元素,从而以不同的速度滚动.
关于这方面有很多资源,@ dwreck08给出的是最好的资源之一:http://keithclark.co.uk/articles/pure-css-parallax-websites/
这是一个快速复制:
.parallax {
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
-webkit-perspective: 1px;
perspective: 1px;
}
.parallax__layer {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.parallax__layer--base {
transform: translateZ(0);
color: white;
background: url(http://cliparts.co/cliparts/pT5/A7L/pT5A7L8T9.png) center no-repeat;
background-size: 50% auto;
}
.parallax__layer--back {
transform: translateZ(-1px) scale(2);
background: url(http://www.hdiphone6wallpapers.net/iphone-6-backgrounds/iphone-6-wallpapers-2/iphone-6-wallpapers-hd-100pb94q-1080x1920.jpg) no-repeat;
}
.parallax__layer--slow {
transform: translateZ(-4px) scale(4);
background: url(http://1.bp.blogspot.com/-ZRDN2sugdrg/UXa1qeFfjYI/AAAAAAAAVjo/1m10L-jCIgo/s1600/starcraft_2_render7E0.png) no-repeat center;
background-size: 100%;
}
* {
margin: 0;
padding: 0;
}
.parallax {
font-size: 16px;
}
.parallax__layer {
padding: 75vh 0;
}Run Code Online (Sandbox Code Playgroud)
<div class="parallax">
<div class="parallax__layer parallax__layer--back">
</div>
<div class="parallax__layer parallax__layer--slow">
</div>
<div class="parallax__layer parallax__layer--base">
</div>
</div>Run Code Online (Sandbox Code Playgroud)
要控制每个图层的滚动速度,请更改translateZ和scale属性.