CSS3动画功能可实现平滑的3D革命?

Pra*_*lia 7 css rotation css3 css-animations

我有这支笔试图模仿一个围绕某事物旋转的物体.这有效,但不顺利.旋转时,它会在左右边缘暂停.

我认为它与某些事情有关animation-timing-function但无法通过任何内置函数(如ease-in-outlinear自定义cubic-bezier函数)获得所需的结果.

如何让动画感觉流畅?如果有更好的方法可以做到这一点,请随时告诉我.

.overlay {
  background-image: -webkit-repeating-linear-gradient(0deg, transparent, transparent 1%, rgb(255, 255, 255) 2%, rgb(255, 255, 255) 2%);
  background-image: repeating-linear-gradient(90deg, transparent, transparent 1%, rgb(255, 255, 255) 2%, rgb(255, 255, 255) 2%);
  height: 200px;
  position: relative;
  width: 40%;
  margin: auto;
}
.circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: #888;
  position: absolute;
  z-index: -1;
  left: 0;
  display: inline-block;
}
.move {
  -webkit-animation: moveAndGlow 2s infinite ease-in-out;
  animation: moveAndGlow 2s infinite ease-in-out;
}
@-webkit-keyframes moveAndGlow {
  25% {
    background: #ccc;
    -webkit-transform: scale(.5);
    transform: scale(.5);
    margin-top: 25px;
  }
  50% {
    left: 100%;
    margin-left: -100px;
    background: #888;
    -webkit-transform: scale(1);
    transform: scale(1);
    margin-top: 0;
  }
  75% {
    background: #000;
    -webkit-transform: scale(1.5);
    transform: scale(1.5);
    margin-top: 25px;
  }
}
@keyframes moveAndGlow {
  25% {
    background: #ccc;
    -webkit-transform: scale(.5);
    transform: scale(.5);
    margin-top: 25px;
  }
  50% {
    left: 100%;
    margin-left: -100px;
    background: #888;
    -webkit-transform: scale(1);
    transform: scale(1);
    margin-top: 0;
  }
  75% {
    background: #000;
    -webkit-transform: scale(1.5);
    transform: scale(1.5);
    margin-top: 25px;
  }
}
Run Code Online (Sandbox Code Playgroud)
<div class="overlay">
  <span class="circle move"></span>
</div>
Run Code Online (Sandbox Code Playgroud)

web*_*iki 4

如果您想在 3D 环境中移动元素,您可以使用透视属性和实际的 3D 旋转。

现在,您正在位置之间的直线上制作动画,因此模拟旋转几乎是不可能的。我构建了以下示例,您需要调整大小以适合您的项目,但您应该明白了。

另请注意,我将渐变背景放入伪元素中,以便它出现在移动对象的前面:

.overlay {
  height: 200px;
  position: relative;
  width: 40%;
  margin: auto;
  perspective:500px;
  margin-top:50px;
}
.overlay:after{
  content:'';
  position:absolute;
  top:-100px; left:-10%;
  width:120%; height:100%;
  background-image: repeating-linear-gradient(90deg, transparent, transparent 1%, rgb(255, 255, 255) 2%, rgb(255, 255, 255) 2%);
}

.circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: #888;
  position: absolute;
  z-index: -1;
  left: 50%;
  margin-left:-50px;
  transform: rotateY(0deg) translateX(-100px) rotateY(0deg);
  display: inline-block;
}

.move {
  animation: moveAndGlow 2s infinite linear;
}

@keyframes moveAndGlow {
  to{  transform:rotateY(360deg) translateX(-100px) rotateY(-360deg); }
}
Run Code Online (Sandbox Code Playgroud)
<div class="overlay">
  <span class="circle move"></span>
</div>
Run Code Online (Sandbox Code Playgroud)