CSS 动画 : Rotate around X-axis?

标签 css animation transform css-animations

所以我来了this google doodle ,我想知道如何使用 CSS 进行这种旋转(谷歌涂鸦是一个 gif)。看起来它只围绕一个轴旋转,如果我在 CSS 中进行旋转,它会围绕 x 和 y 轴旋转。 3D 旋转是否可行(从未使用过,所以我不知道)。

我在 JSfiddle 中做了一个基本示例.

HTML:

<div class="rotatediv">
</div>

CSS:

.rotatediv {
  background-color: red;
  width:500px;
  height:500px;
  animation-name:rotate_animation;
  animation-duration: 15s;
  animation-delay:0s;
  animation-iteration-count: infinite;
}

@keyframes rotate_animation {
  0% {transform: rotate(0deg);}
  100% {transform: rotate(360deg);}
}

最佳答案

诀窍是将一个 div 放在 rotatediv 中,并通过移除其背景颜色使 rotatediv 不可见。改为给 rotatediv 中的 div 设置背景色。

现在借助 position: absolute; 将 div 定位在 rotatediv 中。 父 div 将旋转,子 div 也将旋转,同时保持与父 div 相同的方向。

<img src="https://placehold.it/300x300" />
<div class="rotatediv">
  <div class="object">
    <img src="https://placehold.it/30x30/000000" />
  </div>
</div>

.object {
  text-align: center;
}
img {
  position: absolute;
}

.rotatediv {
  width:300px;
  height:300px;
  animation-name:rotate_animation;
  animation-duration: 15s;
  animation-delay:0s;
  animation-iteration-count: infinite;
}

@keyframes rotate_animation {
  0% {transform: rotate(360deg);}
  100% {transform: rotate(0deg);}
}

https://jsfiddle.net/r8r4hzq2/

关于CSS 动画 : Rotate around X-axis?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43292909/

相关文章:

html - 站点一侧的额外空白

样式中的 CSS 样式?

ios - 在 .onAppear 中切换动画时 SwiftUI 出现意外动画(使用 GeometryReader 的大小)

iOS Swift UIView 动画跳回到开头

css - :before and :after on Firefox with CSS 3D not rendering in order

css - 图像不适合 div 并且当我们执行 ctrl+shift+m​​ 时,所有信息和图像都不在所有 div 中并合并。d

CSS 导航背景颜色仅在滚动到第一部分标签时更改

iphone - UIView 动画完成 block 在其他动画开始时触发

java - 如何将 List<X> 转换为另一个 List<Y>

python - 在使用groupby和transform进行计算时,如何仅在第一次出现时获得聚合结果,而在其他情况下获得0?