body {
height: 150vh;
}
#hero {
position: relative;
border: none;
height: 100vh;
}
#hero .hero-image {
background-image: url(https://images.unsplash.com/photo-1518791841217-8f162f1e1131);
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 95%;
}
#hero .hero-image:after {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: rgba(0,0,0,0.2);
}
#hero .skewhero-mask {
height: 100%;
position: absolute;
top: 0;
left: 10vw;
width: 45vw;
overflow: hidden;
transform: skew(24deg) translateX(0vh) translateY(0%);
}
#hero .skewhero-parallax {
transform: translateX(0vh);
width: 200%;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
#hero .skewhero-image {
background-image: url(https://images.unsplash.com/photo-1518791841217-8f162f1e1131);
height: 100%;
background-size: 110% auto;
background-attachment: fixed;
transform-origin: right top;
transform: skew(-24deg);
}
<section id="hero">
<div class="hero-image">
</div>
<div class="skewhero-mask">
<div class="skewhero-parallax">
<div class="skewhero-image"></div>
</div>
</div>
</section>
我真的被这个困住了。我正在设计一个视差效果,我background-position
使用 jQuery 移动固定背景的属性。jQuery 在这里没有错,所以我不会在此处包含它以降低问题的复杂性。
在 Chrome 中,我得到了想要的效果。在 Firefox 或 Edge 中,这是一场噩梦。我还没有在 Opera 上测试过它。background-attachment: fixed
在这些浏览器中从类中删除时.skewhero-image
,我注意到没有任何区别。该属性没有做任何事情,因为当我在 Chrome 中删除相同的属性时,我会得到与其他浏览器相同的不良结果。
如何更改我的代码以实现与现在在 Chrome 中完全相同的效果,但在所有其他桌面浏览器中也是如此?不包括移动浏览器。
基本上,猫的形象不能移动,只能移动它周围的容器。在 Chrome 中,这可以按预期工作。在 Firefox 或 Edge 中,猫随容器移动,而不是固定在视口上。
编辑:我发现从自身和所有父级中省略所有 transform
属性会将图像修复到视口。有什么可以补救的吗?