Animate an element on a sine path

痞子三分冷 提交于 2019-12-03 03:09:12

You can move an element on a sine path with 2 CSS keyframe animations. The point is to translate left right with a linear timing function and up/down with an ease-in-out timing function.

This requires to translate the container and move the element up and down with 2 different keyframe animations. Here is an example :

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%);}
}
<div>
  <img src="http://i.imgur.com/QdWJXta.png">
</div>

Note that this example doesn't contain vendor prefixes. For more info, see canIuse for:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!