html - 我怎样才能解决这个问题?一个元素上的两个动画?

标签 html css animation css-transitions css-animations

所以我试图以某种方式在一个元素上制作两个动画,但我无法修复它。

这是一个jsfiddle其中只包括重要的事情。如需完整图片,check here .我想制作代表字母 L 的外星人从右到左(= 他现在所在的位置)。

所以我想得到的是外星人从右向左移动,但连同移动的腿,以及外星人的形象。

我将解释一些代码。

HTML:

            <div class="letter_L">

                <div class="monster_L">
                    <img src="http://googledoodle.lucasdebelder.be/images/l/monster.png">
                </div>
                <div class="benen_L">
                    <div class="B_1"></div>
                    <div class="B_2"></div>
                    <div class="B_1 B_3"></div>
                    <div class="B_2 B_4"></div>
                </div>
            </div>

.monster_L 表示外星人的形象

.Benen_L 代表 (=benen)

CSS

/*Monster L*/
.monster_L img {
    position: absolute;
    bottom: 296px;
    left: 596px;
    z-index: 50;
    opacity: 1;
    width: 70px;
}

/*Been1*/
.B_1 {
    position: absolute;
    bottom: 293px;
    left: 597px;
    z-index: 40;
    opacity: 1;
    width: 8px;
    height: 50px;
    background-color: #297f40;
    border-radius: 0 0 15px 15px;

    animation-name: animation_B_1;
    animation-delay: 0s;
    animation-duration: 2s;
    animation-iteration-count: infinite;
    animation-timing-function: ease-in-out;
}
/*Been2*/
.B_2 {
    position: absolute;
    bottom: 286px;
    left: 605px;
    z-index: 40;
    opacity: 1;
    width: 8px;
    height: 50px;
    background-color: #297f40;
    border-radius: 0 0 15px 15px;

    animation-name: animation_B_2;
    animation-delay: 0s;
    animation-duration: 2s;
    animation-iteration-count: infinite;
    animation-timing-function: ease-in-out;
}
/*Been3*/
.B_3 {
    left: 613px;
}
/*Been4*/
.B_4 {
    left: 621px;
}
@keyframes animation_B_1 {
    0%{ bottom: 293px; }
    50% { bottom: 286px; }
    100%{ bottom: 293px; }
}
@keyframes animation_B_2 {
    0%{ bottom: 286px; }
    50% { bottom: 293px; }
    100%{ bottom: 286px; }
}

最佳答案

你必须申请position: absoluteletter_L并申请 keyframe向它翻译 right属性(property)。

但是当你申请position: absoluteposition: relativeletter_L , 所有 position: absolute里面的元素不会相对于 letter_L .所以你改变了top , bottom , left相应地协调。

我已经尽力为您解决了这个问题。

检查更新fiddle .

引用代码:

.letter_L {
  width: 100px;
  position: absolute;
  /* z-index: 100000000; */
  height: 90px;
  animation-name: moveRTL;
  animation-delay: 0s;
  animation-duration: 2s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
}


/*Monster L*/

.monster_L img {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 50;
  opacity: 1;
  width: 70px;
}


/*Been1*/

.B_1 {
  position: absolute;
  top: 32px;
  left: 0;
  z-index: 40;
  opacity: 1;
  width: 8px;
  height: 50px;
  background-color: #297f40;
  border-radius: 0 0 15px 15px;
  animation-name: animation_B_1;
  animation-delay: 0s;
  animation-duration: 2s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
}


/*Been2*/

.B_2 {
  position: absolute;
  top: 32px;
  left: 8px;
  z-index: 40;
  opacity: 1;
  width: 8px;
  height: 50px;
  background-color: #297f40;
  border-radius: 0 0 15px 15px;
  animation-name: animation_B_2;
  animation-delay: 0s;
  animation-duration: 2s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
}


/*Been3*/

.B_3 {
  left: 16px;
}


/*Been4*/

.B_4 {
  left: 24px;
}

@keyframes animation_B_1 {
  0% {
    top: 28px;
  }
  50% {
    top: 32px;
  }
  100% {
    top: 28px;
  }
}

@keyframes animation_B_2 {
  0% {
    top: 32px;
  }
  50% {
    top: 28px;
  }
  100% {
    top: 32px;
  }
}

@keyframes moveRTL {
  0% {
    right: 0;
  }
  100% {
    right: 200px;
  }
}
<!-- L letter -->
<div class="letter_L">
  <div class="monster_L">
    <img src="http://googledoodle.lucasdebelder.be/images/l/monster.png">
  </div>
  <div class="benen_L">
    <div class="B_1"></div>
    <div class="B_2"></div>
    <div class="B_1 B_3"></div>
    <div class="B_2 B_4"></div>
  </div>
</div>

关于html - 我怎样才能解决这个问题?一个元素上的两个动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43252249/

相关文章:

html - 将引用的 HTML5 标签与图像和作者结合起来

html - 是否有一个 javascript 库可以处理整个页面幻灯片?

html - 如何设置嵌套的几个div的相对位置?

animation - isotope.js 的轻量级替代品

animation - 在 SVG 中动画 "depth"

javascript - 是否可以阻止浏览器解析某些元素?

javascript - 在 java 脚本中上传图像时如何限制 .exe 扩展名?/

javascript - 如何根据 URL 在 polymer 元素上执行 select() 方法?

html - 特定类型的第一个子元素

ios - Swift:查看MessageController(iOS消息页面)后iOS动画停止