gpt4 book ai didi

css - RotateX 停止并 overflow hidden

转载 作者:行者123 更新时间:2023-11-28 10:08:22 25 4
gpt4 key购买 nike

我有一个使用关键帧和变换的简单动画,特别是 rotateXrotateZ。动画效果如我所料(至少在 Chrome 中,还没有尝试过其他动画)。

现在我已经可以正常工作了,如果动画元素超出其父元素,我想隐藏它们。我将普通的 overflow: hidden; 放在父级上。

然后 rotateX 就停止渲染了。 rotateZ 按预期继续。奇怪的是,看起来该元素在检查时继续变换,但子元素仅遵循 rotateZ

@keyframes stir {
0% {
transform: rotateX(0deg) rotateZ(-25deg);
}
25% {
transform: rotateX(3deg) rotateZ(0deg);
}
50% {
transform: rotateX(0deg) rotateZ(25deg);
}
75% {
transform: rotateX(-3deg) rotateZ(0deg);
}
100% {
transform: rotateX(0deg) rotateZ(-25deg);
}
}
* {
box-sizing: border-box;
}
.mixing {
position: relative;
width: 80px;
padding-top: 50px;
margin: 50px auto;
}
.mixing .rim,
.mixing .rimb {
width: 80px;
height: 20px;
border: 2px solid #000;
border-radius: 40px / 10px;
background: #fff;
position: relative;
z-index: 5;
}
.mixing .rimb {
z-index: 3;
}
.mixing .sides {
position: relative;
background: #fff;
height: 8px;
width: 100%;
margin: -18px 0 0;
border-left: 2px solid #000;
border-right: 2px solid #000;
top: 10px;
z-index: 4;
}
.mixing .bowl {
width: 70px;
height: 40px;
margin: -16px auto 0;
border: 2px solid #000;
background: #fff;
border-radius: 0 0 30px 30px / 0 0 40px 40px;
}
.mixing .spoon-box {
width: 120px;
height: 70px;
border-radius: 0 0 60px 60px / 0 0 20px 20px;
position: absolute;
top: -2px;
left: -20px;
z-index: 10;
perspective: 25px;
transform-style: preserve-3d;
}
.mixing .spoon {
position: absolute;
left: 50%;
margin-left: -9px;
bottom: -50px;
transform-origin: center bottom;
animation: stir 2s infinite;
animation-timing-function: linear;
}
.mixing .spoon .stick {
height: 55px;
width: 8px;
border: 2px solid #000;
border-radius: 3px 3px 0 0;
border-width: 2px 2px 0px;
background: #fff;
margin: 8px 5px -4px;
position: relative;
z-index: 2;
}
.mixing .spoon .cup {
position: relative;
height: 22px;
width: 18px;
margin-bottom: 40px;
border: 2px solid #000;
background: #fff;
border-radius: 9px / 11px;
}
.broken .spoon-box {
overflow: hidden;
}
<div class="mixing">
<div class="rim"></div>
<div class="sides"></div>
<div class="rimb"></div>
<div class="bowl"></div>
<div class="spoon-box">
<div class="spoon">
<div class="stick"></div>
<div class="cup"></div>
</div>
</div>
</div>
<div class="mixing broken">
<div class="rim"></div>
<div class="sides"></div>
<div class="rimb"></div>
<div class="bowl"></div>
<div class="spoon-box">
<div class="spoon">
<div class="stick"></div>
<div class="cup"></div>
</div>
</div>
</div>

https://codepen.io/freer4/pen/jJNEpP

最佳答案

您是否考虑过使用 clip-path css 规则而不是 overflow: hidden?在对最新的 Firefox 和 Chrome 进行简短测试后,您的 rotateZ 未应用的问题似乎已解决。作为一个不错的奖励,您可以更具体地裁剪,因此要匹配碗的形状,您可以使用 clip-path: ellipse(...),如下图所示:

bowl clipping

但是,请注意,IE and Edge 不支持 clip-path .

修改后的例子可以在这个forked codepen中找到或者在下面的代码片段中:

@keyframes stir {
0% {
transform: rotateX(0deg) rotateZ(-25deg);
}
25% {
transform: rotateX(3deg) rotateZ(0deg);
}
50% {
transform: rotateX(0deg) rotateZ(25deg);
}
75% {
transform: rotateX(-3deg) rotateZ(0deg);
}
100% {
transform: rotateX(0deg) rotateZ(-25deg);
}
}
* {
box-sizing: border-box;
}
.mixing {
position: relative;
width: 80px;
padding-top: 50px;
margin: 50px auto;
}
.mixing .rim,
.mixing .rimb {
width: 80px;
height: 20px;
border: 2px solid #000;
border-radius: 40px / 10px;
background: #fff;
position: relative;
z-index: 5;
}
.mixing .rimb {
z-index: 3;
}
.mixing .sides {
position: relative;
background: #fff;
height: 8px;
width: 100%;
margin: -18px 0 0;
border-left: 2px solid #000;
border-right: 2px solid #000;
top: 10px;
z-index: 4;
}
.mixing .bowl {
width: 70px;
height: 40px;
margin: -16px auto 0;
border: 2px solid #000;
background: #fff;
border-radius: 0 0 30px 30px / 0 0 40px 40px;
}
.mixing .spoon-box {
width: 120px;
height: 70px;
border-radius: 0 0 60px 60px / 0 0 20px 20px;
position: absolute;
top: -2px;
left: -20px;
z-index: 10;
perspective: 25px;
transform-style: preserve-3d;
}
.mixing .spoon {
position: absolute;
left: 50%;
margin-left: -9px;
bottom: -50px;
transform-origin: center bottom;
animation: stir 2s infinite;
animation-timing-function: linear;
}
.mixing .spoon .stick {
height: 55px;
width: 8px;
border: 2px solid #000;
border-radius: 3px 3px 0 0;
border-width: 2px 2px 0px;
background: #fff;
margin: 8px 5px -4px;
position: relative;
z-index: 2;
}
.mixing .spoon .cup {
position: relative;
height: 22px;
width: 18px;
margin-bottom: 40px;
border: 2px solid #000;
background: #fff;
border-radius: 9px / 11px;
}
.broken .spoon-box {
transform-style: preserve-3d;
clip-path: ellipse(80px 49px at 60px 22px);
}
<div class="mixing">
<div class="rim"></div>
<div class="sides"></div>
<div class="rimb"></div>
<div class="bowl"></div>
<div class="spoon-box">
<div class="spoon">
<div class="stick"></div>
<div class="cup"></div>
</div>
</div>
</div>
<div class="mixing broken">
<div class="rim"></div>
<div class="sides"></div>
<div class="rimb"></div>
<div class="bowl"></div>
<div class="spoon-box">
<div class="spoon">
<div class="stick"></div>
<div class="cup"></div>
</div>
</div>
</div>

关于css - RotateX 停止并 overflow hidden ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54853899/

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