html - 遮盖一个对象,使它看起来好像它在它正在旋转的项目后面
问题描述
我正在尝试围绕另一个物体(圆圈)制作一个“点”轨道,但由于z-index
点总是出现在圆圈上方,因此它意味着绕着轨道运行。
CodePen 链接:https ://codepen.io/moy/pen/ROVZXd?editors=1100
理想情况下,动画的第二半将发生在对象后面,所以直到它从另一边出来时才被看到——这可能吗?
我想过淡出正在移动的物体,但我认为这不会产生平滑/蒙版效果?
关于如何掩盖这个区域有点卡住,因为我看不到 CSS 知道它应该被隐藏的方式。我想也许我可以z-index
通过动画更改 50% 并将其重置为 0%/100% 但这似乎没有任何作用。
有任何想法吗?提前致谢!
.earth {
background: white;
border: 1px solid black;
border-radius: 50%;
display: block;
height: 100px;
margin: 30px auto;
position: relative;
width: 100px;
z-index: 20;
}
.orbit {
border: 2px #eee transparent;
border-radius: 50%;
height: 140px;
margin: auto;
position: absolute;
top: -20px;
left: -20px;
transform: rotateZ(60deg) rotateY(60deg);
transform-style: preserve-3d;
width: 140px;
z-index: 10;
}
.orbit .moon {
animation: move ease-in-out infinite;
animation-duration: 2s;
background: black;
border-radius: 50%;
height: 15px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 15px;
z-index: 10;
}
@keyframes move {
0% {
transform: rotateZ(-90deg) translateX(70px) rotateZ(90deg) rotateY(-70deg); z-index: 20;
}
50% {
z-index: -20;
}
100% {
transform: rotateZ(270deg) translateX(70px) rotateZ(-270deg) rotateY(-70deg); z-index: 20;
}
}
<div class="earth">
<div class="orbit">
<div class="moon"></div>
</div>
</div>
解决方案
我似乎已经通过在z-index
应用于父级的动画中添加负数来解决这个问题.orbit
链接:https ://codepen.io/moy/pen/wZdpRw?editors=1100
我最初在动画中应用了 50%,因为这应该是点在它回到大圆圈后面之前最远的地方。但是,这不起作用,将其设置为 100% 确实有效。不完全确定为什么,但它似乎工作!
推荐阅读
- vue.js - 在具有多个组件的 Vue 中单击事件作为父级
- javascript - 'Nuxt generate' 后 Axios POST 不工作
- php - 为什么我无法使用 VichUploaderBundle 和 Symfony 5 在我的网页上显示图像?
- osgi - Karaf Bundle.getState() 与 bundle:list 中的 bundle 状态不完全匹配
- spring - Spring data jpa避免内存分页和n+1使用规范
- reactjs - 试图在特定页面上隐藏父组件
- sas - 打破 SAS 分类的联系
- python - 为什么我的第二个 Jinja for 循环没有运行?
- c++ - 如何防止我的函数的调用者在 C++ 中使用相同的按引用传递变量?
- css - 通过 uBlock Origin 中的 CSS 覆盖修复 div 的宽度