.wrap {
position: absolute;
z-index: 777;
top: 100%;
left: 0;
width: 100%;
min-height: 100%;
background-color: white;
-webkit-overflow-scrolling: touch;
-moz-transform: translateX(25%);
-webkit-transform: translateX(25%);
-o-transform: translateX(25%);
-ms-transform: translateX(25%);
transform: translateX(25%);
}
section {
position: relative;
width: 100%;
display: table;
height: 450px;
border-bottom: 2px solid #E6EAED;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 20px;
background-color: #333;
background-repeat: repeat;
background-position: center center;
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-attachment: fixed;
background-image: url('http://placekitten.com/600/600');
}
请参阅上面的 fiddle 。我在我正在进行的元素中使用了类似的结构。这是一个包含交替部分的页面,一个用于内容,一个用作带有覆盖物和固定背景图像的分隔线。
工作正常,但由于某些原因,当对具有固定背景的元素或其父元素应用转换时,背景完全消失或留下一些伪像和部分图像。
在任何其他浏览器中工作正常。一直没有找到解决方案,所以我希望有人可以帮助我解决这个问题。
提前致谢!
最佳答案
我遇到了同样的问题,只是在 Chrome 中。这是我的解决方案:
// run js if Chrome is being used
if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
// set background-attachment back to the default of 'scroll'
$('.imagebg').css('background-attachment', 'scroll');
// move the background-position according to the div's y position
$(window).scroll(function(){
scrollTop = $(window).scrollTop();
photoTop = $('.imagebg').offset().top;
distance = (photoTop - scrollTop);
$('.imagebg').css('background-position', 'center ' + (distance*-1) + 'px');
});
}
关于css - WebKit 翻译 + 修复背景附件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16901888/