【问题标题】:CSS animation:How to make the image object bounce back seamlessly?CSS动画:如何让图片对象无缝反弹?
【发布时间】:2016-12-10 05:18:14
【问题描述】:

演示: http://www.suanle.lol/move.php

在动画演示中,您可以看到当鸡蛋刚要弹回来时,它会闪出一秒钟然后闪入。这使动画中断。所以我想知道为什么会发生这种情况以及如何解决它?

如果你想查看 Gif:

其实不只限于.gif,任何格式的图片都会出现问题。

代码如下:

#egg {
  z-index: 2;
  margin-left: 50px;
  /*display: none;*/
  position: absolute;
  animation-duration: 6.4s;
  animation-name: slide;
  animation-iteration-count: infinite;
  /*animation: pulse 5s infinite;*/
}
@keyframes slide {
  0% {
    margin-left: 10px;
    /*width: 300%; */
  }
  49% {
    -moz-transform: scaleX(1);
    -o-transform: scaleX(1);
    -webkit-transform: scaleX(1);
    transform: scaleX(1);
    filter: FlipH;
    -ms-filter: "FlipH";
  }
  50% {
    margin-left: 350px;
    -moz-transform: scaleX(-1);
    -o-transform: scaleX(-1);
    -webkit-transform: scaleX(-1);
    transform: scaleX(-1);
    filter: FlipH;
    -ms-filter: "FlipH";
  }
  100% {
    margin-left: 10px;
    -moz-transform: scaleX(-1);
    -o-transform: scaleX(-1);
    -webkit-transform: scaleX(-1);
    transform: scaleX(-1);
    filter: FlipH;
    -ms-filter: "FlipH";
  }
}
<img id="egg" src="http://i.stack.imgur.com/Ke7wO.gif">

【问题讨论】:

  • 这是因为它从动画的49% 上的scaleX(1) 移动到50% 上的scaleX(-1) 的那一刻
  • 将 49% 更改为 49.9%..

标签: html css animation gif


【解决方案1】:

好的,这看起来好多了,将 49% 更改为 49.9% 并增强了一点,问题是这个 1% 6.4s 的动画持续时间仍然很明显,这使它“闪烁”。

通过减少从 1%0.1% 的差异,从 scaleX(1) 转换到 scaleX(-1) 所需的时间并不明显

jsFiddle

#container {
  position: absolute;
  background-color: rgb(231, 143, 128);
  width: 310px;
  height: 42px;
  margin-left: 50px;
  z-index: 1;
}
#egg {
  z-index: 2;
  margin-left: 50px;
  /*display: none;*/
  position: absolute;
  animation-duration: 6.4s;
  animation-name: slide;
  animation-iteration-count: infinite;
  /*animation: pulse 5s infinite;*/
}
@keyframes slide {
  0% {
    margin-left: 10px;
    /*width: 300%; */
  }
  49.9% {
    -moz-transform: scaleX(1);
    -o-transform: scaleX(1);
    -webkit-transform: scaleX(1);
    transform: scaleX(1);
    filter: FlipH;
    -ms-filter: "FlipH";
  }
  50% {
    margin-left: 350px;
    -moz-transform: scaleX(-1);
    -o-transform: scaleX(-1);
    -webkit-transform: scaleX(-1);
    transform: scaleX(-1);
    filter: FlipH;
    -ms-filter: "FlipH";
  }
  100% {
    margin-left: 10px;
    -moz-transform: scaleX(-1);
    -o-transform: scaleX(-1);
    -webkit-transform: scaleX(-1);
    transform: scaleX(-1);
    filter: FlipH;
    -ms-filter: "FlipH";
  }
}
<img id="egg" src="http://i.stack.imgur.com/Ke7wO.gif">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    • 2017-04-15
    • 2020-09-26
    • 2022-01-22
    • 1970-01-01
    • 2021-05-14
    • 2021-11-24
    相关资源
    最近更新 更多