为正弦路径上的元素设置动画

Sag*_*dte 8 css css3 css-transitions css-animations

元素动画的正弦波或曲线路径 我需要在正弦波或路径上移动一个元素,如上图所示.我做了些什么.但它并没有按照我的意愿运作.

img {
  position:absolute;
  animation: roam infinite;
  animation-duration: 15s;
}

@keyframes roam {
  0% { left: 50px; top:100px }
  10%{ left:100px; top:100px }
  20%{ left:200px; top:200px }
  30%{ left:300px; top:50px }
  40%{ left:400px; top:200px }
	
}
Run Code Online (Sandbox Code Playgroud)
<img src="https://developer.chrome.com/extensions/examples/api/idle/idle_simple/sample-128.png">
Run Code Online (Sandbox Code Playgroud)

web*_*iki 22

您可以使用2个CSS 关键帧动画在正弦路径上移动元素.重点是通过线性定时功能向左平移,向上/向下平移,具有易于进行的定时功能.

这需要翻译容器并使用2个不同的关键帧动画上下移动元素.这是一个例子:

div{
  position:absolute;
  left:0;
  width:10%;
  animation: translate 15s infinite linear;
}
img {
  position:absolute;
  animation: upDown 1.5s alternate infinite ease-in-out;
  width:100%;
}

@keyframes upDown {
  to { transform: translatey(100px);}
}
@keyframes translate {
  to { transform: translatex(900%);}
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <img src="http://i.imgur.com/QdWJXta.png">
</div>
Run Code Online (Sandbox Code Playgroud)

请注意,此示例不包含供应商前缀.有关更多信息,请参阅canIuse: