css - 如何创建不随背景图像跳跃的关键帧平滑连续循环?

标签 css css-animations keyframe

我创建了一个带有背景图片的 div。使用关键帧动画,我希望它连续垂直向上移动,但它会在帧的末尾跳跃然后继续。我是关键帧的新手。我不会用 JS。

我已尝试查看此处的问题,但它们主要集中在 slider 上。

到目前为止,这是我的代码:

<style>
#animate-area   { 
    background-image: url(/image.png);
    width: 100%;
    height: 500px;
    background-position: 0px 0px;
    background-repeat: repeat-x;

    -webkit-animation: animatedBackground 5s ease-in-out infinite;
    -moz-animation: animatedBackground 5s ease-in-out infinite;
    animation: animatedBackground 5s ease-in-out infinite;
}

@-webkit-keyframes animatedBackground {
   from { background-position: 0 0; }
   to { background-position: 0 100%; }
}

@-moz-keyframes animatedBackground {
   from { background-position: 0 0; }
   to { background-position: 0 100%; }
}

@keyframes animatedBackground {
   from { background-position: 0 0; }
   to { background-position: 0 100%; }
}
</style>

<div id="animate-area"></div>

一旦帧完成,它就会跳转然后继续。是否可以让它连续循环而不用背景图像跳转?如果是,怎么办?

最佳答案

不断向上移动的实例:

#animate-area {
  background-image: url('https://pt.freelogodesign.org/Content/img/logo-ex-2.png');
  width: 100%;
  height: 500px;

  background-position: 0;
 animation: slideup 5s linear 1s infinite;
 
 position:absolute;
}

@keyframes slideup {
  0% { background-position: 0 0; }
  50% { background-position: 0 -500px; }
  100% { background-position: 0 -900px; }
}
<div id="animate-area"></div>

关于css - 如何创建不随背景图像跳跃的关键帧平滑连续循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57030027/

相关文章:

javascript - 单击其他 DIV 时更改 DIV 颜色

javascript - 如何在 CSS 中向下移动剪贴蒙版?

html - @keyframe 不适用于 mozilla

html - CSS3 关键帧和变换不能正确显示立方体

css 不透明度影响同级图像不透明度

html - 通过 Bootstrap 在具有不同文本长度的面板框中创建相同的高度

jquery - HTML/CSS 输入焦点超出范围

css - 在 Firefox 60 或更早版本中为 SVG 剪辑路径设置动画时出现随机方 block

javascript - 更简洁的 css/sass 关键帧代码编写方式

html - 如何在关键帧期间重置每个之间的原点时进行 2+ 次旋转?