【问题标题】:translate3d() causes clipping in Safaritranslate3d() 导致 Safari 中的剪辑
【发布时间】:2023-04-06 14:36:01
【问题描述】:

我正在开发一个严重依赖绝对定位、CSS 变换和 CSS 过渡的网络应用程序。

我的标记:

<div class="wrapper">
    <div class="background" ></div>
    <div class="foreground" >
        <div class="image" ></div>
    </div>
</div>​

我的 CSS

.wrapper{
    -webkit-perspective: 1600;
    -webkit-perspective-origin-y: 30%;
    height: 500px;
    width: 100%;
}

.background{
    position: absolute;
    background-size: 100% 100%;
    background-image: url("http://farm9.staticflickr.com/8321/8038059897_403c567211.jpg");
    background-color: transparent;
    position: absolute;
    width: 100%;
    height: 300px;
    bottom: 0;
    pointer-events: none;
    -webkit-transform:translate3d(0px,0px,0px);
}

.foreground{
    position: absolute;
    top: 5%;
    bottom: 5%;
    left: 5%;
    right: 5%;
    -webkit-transform: rotateY(25deg);
}

.foreground .image{
    background-image: url("http://farm7.staticflickr.com/6139/6198476123_754eaa1920_m.jpg");
    position: absolute;
    background-size: 100% 100%;
    min-width: 100%;
    min-height: 100%;
    -webkit-transform:translate3d(0px,10px,0px);
}

您可以在http://jsfiddle.net/KjG3f/24/看到它的实际应用

如果您在 Safari(桌面和 iOS)中查看示例,您会看到前景图像被背景剪切。但是,在 Chrome 中,它似乎可以正常工作。

从背景中删除 translate3d() 似乎会导致渲染工作,但我需要 translate3d() 用于动画目的。

先发制人的感谢您的帮助。 ​

【问题讨论】:

    标签: css safari webkit translate3d


    【解决方案1】:

    我认为这是 Chrome 中的一个错误,并且确实存在两个关于它的问题(http://code.google.com/p/chromium/issues/detail?id=116710 和 http://code.google.com/p/chromium/issues/detail?id=102673)。 Firefox 表现出相同的行为。

    Safari 的做法很有意义...当您在 3D 空间中旋转前景图像时,它应该剪切其后面的图像,因为它们位于同一平面上。如果您更改前景或背景元素上的 translate3d Z 值,您可以将它们向前或向后移动到它们不相交的位置。

    不幸的是,跨浏览器对 3D 变换的支持仍然很弱,祝你好运!

    【讨论】:

    • 一个有效的点。我猜剪辑应该正在发生。唔。我想我真正的问题变成了,“我如何使用 translate3d() 定位一个项目以使其不会剪辑?”但是您的答案是正确的,并且在回答原始问题方面做得很好。谢谢!
    • 我认为最好的办法是将它们放置在不剪裁的位置是更改 translate3d(x,y,z) 中的 Z 值。您可以通过调整 Z 值将背景推得更远,直到它不再在 Safari 中剪辑。为了适应向后移动时大小的变化,您可以添加一个 scale() 以使其看起来更大。我没有玩过这个,但我认为你应该能够让它在两个浏览器中看起来都一样。
    猜你喜欢
    • 2019-07-02
    • 1970-01-01
    • 2016-02-28
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2011-05-28
    相关资源
    最近更新 更多