简体   繁体   English

复杂的Webkit Bug? 相对位置+ Z-Index +溢出隐藏+ CSS3变换

[英]Complex Webkit Bug? Relative Position + Z-Index + Overflow Hidden + CSS3 Transform

The code ( JSFiddle Preview ) below produces unexpected results in Webkit in comparison to other modern browsers: 下面的代码( JSFiddle Preview )与其他现代浏览器相比,在Webkit中产生了意想不到的结果:

<script type="text/javascript">
jQuery(document).ready(function($) {
    RunFunction();

    $('.ColorSquare').click(function() {
        $('#Lightbox').css('display','block');
        $('#ShowColorSquare').css('display','block');
        $('#ShowColorSquare').css('z-index','10');
        $('#ShowColorSquare').css('left',$('#ShowColorSquare').parent().width() / 2 - 50);
        $('#ShowColorSquare').css('top',$('#ShowColorSquare').parent().height() / 2 - 50);
        $('#ShowColorSquare').html('The color is: ' + $(this).css('background-color'));
    });
    $('#ShowColorSquare').click(function() {
        $('#Lightbox').css('display','none');
        $('#ShowColorSquare').css('display','none');
        $('#ShowColorSquare').html('');
    });
    $('#Lightbox').click(function() {
        $('#Lightbox').css('display','none');
        $('#ShowColorSquare').css('display','none');
        $('#ShowColorSquare').html('');
    });
});
function RunFunction() {
    $('#slide1').animate({
        left: '-=310'
    }, 3000);
    $('#slide2').animate({
        left: '-=310'
    }, 3000);
    $('#slide3').animate({
        left: '-=310'
    }, 3000, function() {
        if($('#slide1').css("left") == '-310px') {
            $('#slide1').css("left",620);
        }
        if($('#slide2').css("left") == '-310px') {
            $('#slide2').css("left",620);
        }
        if($('#slide3').css("left") == '-310px') {
            $('#slide3').css("left",620);
        }   
        RunFunction(); 
    });
}
</script>
<style>
#Spin {
    width:50px;
    height:50px;
    margin: 15px 0px 15px 15px;
    background-color:#960;
    animation-name:Spin;
    animation-duration:5s;
    transform-origin:50% 50%;
    animation-iteration-count:infinite;

    -webkit-animation-name:Spin;
    -webkit-animation-duration:5s;
    -webkit-transform-origin:50% 50%;
    -webkit-animation-iteration-count:infinite;
}
@keyframes Spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
@-webkit-keyframes Spin {
    0% { -webkit-transform: rotate(0deg); }
    100% { -webkit-transform: rotate(360deg); }
}
.ColorSquare {
    height:100px;
    width:100px;
    position:absolute;
}
#ShowColorSquare {
    height:100px;
    width:100px;
    position:absolute;
    background-color:white;
    display:none;
}
#Lightbox {
    background-color:#000;
    width:100%;
    height:100%;
    position:fixed;
    top:0px;
    left:0px;
    opacity:.8;
    display:none;
    z-index:5;
}
.Panel {
    width:225px;
    height:250px;
    position:absolute;
    background-color:#6C6C6C;
}
</style>

<div id="Spin"></div>

<div style="height:260px;width:500px;overflow-x:hidden;background:#CCC;">
    <div style="height:250px;width:500px;position:relative;">
        <div id="slide1" class="Panel" style="top:0px;left:0px;">
            <div>Slide 1</div>
            <div style="position:relative;margin-top:10px;width:225px;height:200px;">
                <div class="ColorSquare" style="background-color:#093;left:0px;top:0px;"></div>
                <div class="ColorSquare" style="background-color:#C9F;left:100px;top:100px;"></div>
            </div>
        </div>
        <div id="slide2" class="Panel" style="top:0px;left:310px;">
            <div>Slide 2</div>
            <div style="position:relative;margin-top:10px;width:225px;height:200px;">
                <div class="ColorSquare" style="background-color:#CF9;left:0px;top:0px;"></div>
                <div class="ColorSquare" style="background-color:#C63;left:100px;top:100px;"></div>
            </div>
        </div>
        <div id="slide3" class="Panel" style="top:0px;left:620px;">
            <div>Slide 3</div>
            <div style="position:relative;margin-top:10px;width:225px;height:200px;">
                <div class="ColorSquare" style="background-color:#696;left:0px;top:0px;"></div>
                <div class="ColorSquare" style="background-color:#F96;left:100px;top:100px;"></div>
            </div>
        </div>
        <div id="ShowColorSquare"></div>
    </div>
</div>
<div id="Lightbox"></div>

Expected Results: It's supposed to have 3 DIVs (slides) continuously animate to the left in a loop, including the respected colored boxes within the slides. 预期的结果:它应该有3个DIV(幻灯片)在循环中连续动画到左边,包括幻灯片中受尊重的彩色框。 If you click on a colored box, a lightbox shows with the RBG color of the colored box clicked within the respected slide. 如果单击彩色框,则会显示一个灯箱,其中在所关注的幻灯片中单击了彩色框的RBG颜色。 Click again to close the lightbox. 再次单击以关闭灯箱。 All while a 3D transform is applied before the light gray parent DIV, with position relative with overflow hidden, with Jquery animate on absolute positioning slide DIVs. 在浅灰色父DIV之前应用3D变换,同时隐藏溢出的位置,在绝对定位幻灯片DIV上使用Jquery动画。

Results in Webkit: The colored boxes within the slides don't appear to move/render at all until you resize the browser window on a desktop, or click the JSFiddle panel resize handle (or pinch/zoon) on a tablet. Webkit中的结果:在您在桌面上调整浏览器窗口大小或在平板电脑上单击JSFiddle面板调整大小手柄(或捏/ zoon)之前,幻灯片中的彩色框似乎根本不会移动/渲染。 On a different debug note, if the 3D transform animation is not looping, when the animation stops, DIVs render as expected. 在不同的调试注释中,如果3D变换动画未循环,则当动画停止时,DIV将按预期进行渲染。

Test results showing Webkit bug: 显示Webkit错误的测试结果:

  • Win7 IE10: Pass Win7 IE10:通过
  • Win7 Chrome: Pass Win7 Chrome:通过
  • Win7 FF: Pass Win7 FF:通过
  • Win7 Safari: Fail Win7 Safari:失败
  • Win8 IE11: Pass Win8 IE11:通过
  • Android Chrome: Fail Android Chrome:失败
  • iOS Safari: Fail iOS Safari:失败
  • iOS Chrome: Fail iOS Chrome:失败
  • MacOS Safari: Fail MacOS Safari:失败
  • MacOS Chrome: Fail MacOS Chrome:失败

Notice ( JSFiddle Preview ) without the 3D transform, the code works, although the animation is not smooth on desktop. 注意( JSFiddle Preview )没有3D变换,代码可以工作,虽然动画在桌面上不流畅。 The lightbox works fine. 灯箱工作正常。

Notice ( JSFiddle Preview ) with the 3D transform after the parent DIV, the animation is smooth and the lightbox works fine. 注意( JSFiddle Preview )在父DIV之后使用3D变换,动画流畅且灯箱工作正常。

Notice ( JSFiddle Preview ) with -webkit-transform: rotate(0deg) applied to the parent DIV with the overflow, the animation is choppy on tablets, but the 3D transform can exist before the parent DIV or within the slide DIVs. 注意( JSFiddle Preview )使用-webkit-transform:rotate(0deg)应用于具有溢出的父DIV,动画在平板电脑上不稳定,但3D转换可以存在于父DIV之前或幻灯片DIV中。 Another problem is created though. 但是创建了另一个问题。 The parent overflow DIV has a lower z-index than the lightbox, making the dark lightbox DIV appear above the white dialog DIV that's within the parent DIV. 父溢出DIV的z-index低于灯箱,使得暗灯箱DIV显示在父DIV内的白色对话框DIV上方。

I know this is a very weird example, but it's a watered down example of more private complex code. 我知道这是一个非常奇怪的例子,但它是一个更私密的复杂代码的淡化例子。 The 3D transform must be before the parent DIV, or within a slide. 3D变换必须在父DIV之前或幻灯片中。 The lightbox dialog must be within the parent DIV or slide, but appear above the dark lightbox DIV, which can't be within the parent DIV because the overflow hidden will not make the dark lightbox DIV appear full browser screen. 灯箱对话框必须在父DIV或幻灯片内,但显示在暗灯箱DIV上方,不能在父DIV内,因为隐藏的溢出不会使暗灯箱DIV显示为完整的浏览器屏幕。

Any help is appreciated. 任何帮助表示赞赏。

If you read up on GPU Accelerated Compositing in Chrome http://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome you'll find that a renderLayer will get it's own compositing layer when: 如果您在Chrome上阅读GPU加速合成http://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome,您会发现renderLayer会在以下情况下获得自己的合成层:

  1. Layer has 3D or perspective transform CSS properties 图层具有3D或透视变换CSS属性
  2. Layer is used by video element using accelerated video decoding 视频元素使用加速视频解码来使用层
  3. Layer is used by a canvas element with a 3D or 2D context 图层由具有3D或2D上下文的canvas元素使用
  4. Layer uses a CSS animation for its opacity or uses an animated webkit transform Layer使用CSS动画作为其不透明度或使用动画webkit转换
  5. Layer has a descendant that has a compositing layer 图层具有一个具有合成图层的后代
  6. Layer has a sibling with a lower z-index which has a compositing layer (in other words the layer is rendered on top of a composited layer) 图层具有较低z-index的兄弟,该z-index具有合成图层(换句话说,图层在合成图层的顶部呈现)

You're getting different results when you add or remove the 3D transform because the code either goes through the GPU accelerated path, or the software rendering path. 添加或删除3D变换时,您会得到不同的结果,因为代码要么通过GPU加速路径,要么通过软件渲染路径。 The GPU accelerated path is very sensitive to what GPU/drivers you have and if you see any sort of strange graphical glitches, one of the first things you should check is if they still exist when you turn off hardware acceleration off in chrome://flags/ GPU加速路径对你拥有的GPU /驱动程序非常敏感,如果你看到任何奇怪的图形故障,你应该检查的第一件事是当你在chrome中关闭硬件加速时它们是否仍然存在://标志/

All three examples work for me on Chrome OSX, so this is likely a browser bug with a specific graphics card. 这三个示例都适用于Chrome OSX,因此这可能是特定图形卡的浏览器错误。 If you can find a base case I would suggest reporting this bug to the chromium project with your GPU info. 如果你能找到一个基本案例,我会建议用你的GPU信息向chrome项目报告这个bug。

I think Hardware Acceleration maybe the problem .. You can have a look at this question and the accepted answer... 我认为硬件加速可能是问题..你可以看看这个问题和接受的答案......

Chk this Chk这个

try chrome://gpu and look for the difference .. 尝试chrome://gpu并寻找差异..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM