gpt4 book ai didi

css - Chrome CSS 错误 : "translate3d" inside a rotated element does not obey "overflow: hidden"

转载 作者:技术小花猫 更新时间:2023-10-29 10:23:27 28 4
gpt4 key购买 nike

看看这个CodePen明白我的意思:

.perspective-container {
margin: 50px 0;
perspective: 1000px;
perspective-origin: 0 50%;
}
.card {
border: 10px solid blue;
width: 300px;
height: 300px;
overflow: hidden;
transform: rotateY(-45deg);
}
.card-inner {
width: 300px;
height: 300px;
overflow: hidden;
}
.scroller {
transform: translate(0, -100px);
}
.scroller-3d {
transform: translate3d(0, -100px, 0);
}
.will-change {
will-change: transform;
}
<h1>Incorrect (uses will-change):</h1>
<div class="perspective-container">
<div class="card"><div class="card-inner">
<div class="scroll-container">
<div class="scroller will-change">
<img src="https://images2.pixlis.com/background-image-horizontal-lines-and-stripes-seamless-tileable-grey-black-22hnju.png" />
</div>
</div>
</div></div>
</div>
<h1>Incorrect (uses translate3d):</h1>
<div class="perspective-container">
<div class="card">
<div class="scroll-container">
<div class="scroller-3d">
<img src="https://images2.pixlis.com/background-image-horizontal-lines-and-stripes-seamless-tileable-grey-black-22hnju.png" />
</div>
</div>
</div>
</div>
<h1>Correct (uses neither translate3d or will-change):</h1>
<div class="perspective-container">
<div class="card">
<div class="scroll-container">
<div class="scroller">
<img src="https://images2.pixlis.com/background-image-horizontal-lines-and-stripes-seamless-tileable-grey-black-22hnju.png" />
</div>
</div>
</div>
</div>

我有一个应用了透视的旋转元素,在其中我有一个垂直变换的“滚动”div(想象一下杂志翻页体验,每个页面内都有滚动 div)。我将 will-change: transform 添加到内部 div,这破坏了外部容器 overflow: hidden。这似乎是 Chrome 合成器的一个错误。

有人知道任何解决方法吗?我想保留 will-change 属性,因为它可以显着加快移动 Chrome 上的动画速度。

编辑:看起来这不是特定于 will-change 属性,而是任何使内部 div 成为自己的合成层的属性。当我删除 will-change 属性但将转换更改为 translate3d 时,这同样提高了性能并显示了错误。内部 div 上唯一允许旋转的父级正确呈现 overflow: hidden 的类是添加 2D 转换的类。

最佳答案

尝试这样的事情 CodePen :

.container {
margin: 75px 0;
}

.card {
border: 10px solid blue;
width: 300px;
height: 300px;
overflow: hidden;
-webkit-transform: perspective(1000px) rotateY(-45deg);
transform: perspective(1000px) rotateY(-45deg);
-webkit-transform-origin: 0 50%;
transform-origin: 0 50%;
}

.scroller {
-webkit-transform: translate(0, -100px);
transform: translate(0, -100px);
}

.scroller-3d {
-webkit-transform: translate3d(0, -100px, 0);
transform: translate3d(0, -100px, 0);
}

.will-change {
will-change: transform;
}
<h1>Uses will-change:</h1>
<div class="container">
<div class="card">
<div class="scroll-container">
<div class="scroller will-change">
<img src="https://images2.pixlis.com/background-image-horizontal-lines-and-stripes-seamless-tileable-grey-black-22hnju.png" />
</div>
</div>
</div>
</div>

<h1>Uses translate3d:</h1>
<div class="container">
<div class="card">
<div class="scroll-container">
<div class="scroller-3d">
<img src="https://images2.pixlis.com/background-image-horizontal-lines-and-stripes-seamless-tileable-grey-black-22hnju.png" />
</div>
</div>
</div>
</div>

<h1>Uses neither translate3d or will-change:</h1>
<div class="container">
<div class="card">
<div class="scroll-container">
<div class="scroller">
<img src="https://images2.pixlis.com/background-image-horizontal-lines-and-stripes-seamless-tileable-grey-black-22hnju.png" />
</div>
</div>
</div>
</div>

您可以使用 perspective()transform-origin 值。

关于css - Chrome CSS 错误 : "translate3d" inside a rotated element does not obey "overflow: hidden",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29909089/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com