【发布时间】:2016-03-02 20:25:37
【问题描述】:
有问题的设计是:http://hthworldwide.net/
我专门尝试重新创建在滚动时淡化不透明度以在背景中显示固定图像的着陆/英雄元素。
我已经接近了,但我似乎无法确定这件事。问题是如果不给透明字母提供白色背景,我就无法让白色滤镜在整个屏幕上伸展。理想情况下,您应该能够通过文本看到背景图像,如示例所示。
这是我目前所拥有的:http://codepen.io/rsprice/pen/reVazo
html:
<div class="background"></div>
<div class="opacity-layer"></div>
<div class="text"></div>
<div class="other"></div>
css:
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
.background {
width: 3000px;
height: 1000px;
background-position: 0px -300px;
background-size: 130%;
box-sizing: border-box;
z-index: -1;
position: fixed;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
margin: 0;
padding: 0;
color: white;
background: url('https://images.unsplash.com/photo-1454496522488-7a8e488e8606?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=a9504411622da8e65df977606f82479c');
}
.opacity-layer {
transform: rotateZ(360deg);
-webkit-perspective: 1000;
box-sizing: border-box;
position: relative;
width: 2000px;
min-height: 100%;
background-size: cover;
background-position: center top;
overflow: hidden;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
margin: 0;
padding: 0;
}
.text {
height: 300px;
width: 100%;
background-position: center;
background: url('http://hthworldwide.net/sites/all/themes/hthworldwide/style/images/home-intro.png') no-repeat;
background-color: transparent;
padding: 0;
margin: 0;
}
.text img {
margin: 0 auto;
}
.other {
height: 2000px;
}
jQuery:
$(window).scroll(function(){
$(".opacity-layer").css("opacity", 1 - $(window).scrollTop() / 250);
});
【问题讨论】:
标签: jquery html css responsive-design