【问题标题】:How can i move images up to down using keyframe如何使用关键帧上下移动图像
【发布时间】:2018-09-11 21:18:40
【问题描述】:

我希望我的图像以 top:0 开头并以 bottom:0 结尾并具有流畅的动画效果。我正在努力寻找解决方案。

非常清楚,我不能将背景图片用于 SEO 目的。也欢迎 JS 解决方案。

.element {
  height: 200px;
  width: 400px;
  background-color: red;
  position: relative;
  margin: auto;
  overflow: hidden;
}

.element img {
  animation: nudge 5s linear infinite alternate;
  position: absolute;
  top: 0;
  left: 0;
}

@keyframes nudge {
  0%, 100% {
    top: 0;
    bottom: auto;
  }

  50% {
    bottom: 0%;
    top: auto;
  }
}
<div class="element">
  <img src="https://www.neelnetworks.com/wp-content/uploads/2018/08/ecommerce-bg.png" alt=""></div>

【问题讨论】:

  • 使用动画定时功能:ease-in-out;
  • 有多个图像..我不知道图像高度..
  • 不..我希望它从头开始

标签: css css-animations keyframe


【解决方案1】:

您可以在 translateY 上设置动画并使用 top 将其向下移动,这样它就不会离开屏幕,而不是尝试在顶部和底部设置动画

.element {
  height: 200px;
  width: 400px;
  background-color: red;
  position: relative;
  margin: auto;
  overflow: hidden;
}

.element img {
  animation: nudge 2s linear infinite alternate;
  position: absolute;
  top: 0;
  transform: translateY(0);
}

@keyframes nudge {
  100% {
    transform: translateY(-100%);
    top: 100%;
  }
}
&lt;div class="element"&gt;&lt;img src="https://www.neelnetworks.com/wp-content/uploads/2018/08/ecommerce-bg.png" alt=""&gt;&lt;/div&gt;

【讨论】:

  • 我有多个高度的 div。有些是 200 像素,有些是 400 像素等。否则你的答案很好
  • 好吧,我编辑了它,所以你不再需要高度了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 2020-01-07
相关资源
最近更新 更多