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

标签 css css-transitions css-animations

sine wave or curve path for element animation 我需要在正弦波或路径上移动元素,如上图所示。我做了一些东西。但它没有按我的意愿工作。

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 }
	
}
<img src="https://developer.chrome.com/extensions/examples/api/idle/idle_simple/sample-128.png">

最佳答案

您可以使用 2 CSS在正弦路径上移动元素 keyframe animations .重点是用线性 timing function 左右平移以及带有缓入缓出计时功能的上/下。

这需要平移容器并上下移动元素使用 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%);}
}
<div>
  <img src="http://i.imgur.com/QdWJXta.png">
</div>

请注意,此示例不包含供应商前缀。有关详细信息,请参阅可以用于:

关于css - 为正弦路径上的元素设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36618548/

相关文章:

javascript - CKEditor editor.resize() 在 jQuery 中不起作用

html - 我如何用 css 重现这个?

带有 :before opacity transition not working properly 的 css3 三 Angular 形

html - 如何在其容器内为元素从左上角到右下角设置动画?

jquery - 将 CSS3 转换和动画与 jQuery addClass/removeClass 结合使用的最佳方法是什么?

jquery - 使用当前背景颜色的 CSS 关键帧动画

javascript - 将对象拖到父对象之外

CSS3 过渡到高度自动首先到达高度 0

html - 当用户停止使用 CSS 将鼠标悬停在图像上时播放动画

html - 即使分辨率独立对齐,按钮也不居中