css - WebKit 翻译 + 修复背景附件错误

标签 css google-chrome webkit

http://jsfiddle.net/MR94s/

.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/

相关文章:

css - html图片路径不正确

javascript - Chrome 打印预览 : any text on the bottom of every page

macos - 如何设置 WebView 使用的 WebKit 版本...?

html - Chrome 中小型 <input type ='button'> 上的 CSS Sprite

jquery - CSS3 3D图像过渡组合

jquery - 如何在不更改背景 css 的情况下制作模态对话框?

javascript - 简单的 Javascript 画廊 - 缩略图不会居中对齐

javascript - 使粘性/固定元素停在页脚处

javascript - Chrome 将 Notification.requestPermission() 的结果 'default' 视为 'denied'

google-chrome - 一直扫描网址-Chrome扩展程序