【问题标题】:Animation with css [closed]带有css的动画[关闭]
【发布时间】:2018-05-30 14:35:14
【问题描述】:

我想将左侧对象移动到红色框然后隐藏它,然后我想在红色框附近显示右侧对象,然后该对象也将从红色框移动到页面右侧. 这个怎么做? 解释 - 点击这里 Image Link

【问题讨论】:

标签: javascript html css


【解决方案1】:

刚刚挑战了自己。您可以在相对定位的容器中使用绝对定位,并在第二个对象处延迟动画彼此的绝对位置。

.all_container {
  position: relative;
  width: 100%;
  height: 50px;
}

.man_prev {
  position: absolute;
  left: 0;
  top: 10px;
  width: 40px;
  height: 40px;
  background: blue;
  z-index: 1;
  animation-name: man_prev;
  animation-duration: 3s;
  animation-delay: 0s;
  animation-fill-mode: forwards;
  animation-iteration-count: infinite;
}

.red_box {
  position: absolute;
  left: 50%;
  transform: translateX(-50%); /* to center it */
  top: 0;
  width: 60px;
  height: 60px;
  background: red;
  z-index: 2;
}

.man_next {
  position: absolute;
  left: 50%;
  transform: translateX(-50%); /* to center it */
  top: 10px;
  width: 40px;
  height: 40px;
  background: green;
  z-index: 1;
  animation-name: man_next;
  animation-duration: 3s;
  animation-delay: 2.3s;
  animation-fill-mode: forwards;
  animation-iteration-count: infinite;
}

@keyframes man_prev {
    from {left: 0;}
    to {left: 50%; transform: translateX(-50%);}
}

@keyframes man_next {
    from {left: 50%; transform: translateX(-50%);}
    to {left: 100%; transform: translateX(-100%);}
}
<div class="all_container">
  <div class="man_prev"></div>
  <div class="red_box"></div>
  <div class="man_next"></div>
</div>

【讨论】:

  • 非常感谢.. 它有效。但是你知道如何在循环模式下运行这个动画吗?
  • 更新了我的答案。
  • 是的。再次感谢
  • 如果您认为这是正确的答案,您可以接受。
  • 我想再问一个问题,不是这个,但系统不允许我这样做。
【解决方案2】:

尝试像这样具有转换延迟的转换属性

更多信息请阅读this

 

.a {
    left :0;
    transition: left 2s linear 0s, opacity 0s linear 2s;
}
.b {
    left :50%;
}
.c {
    left: 50%;
    transition: opacity 0s linear 2s, left 2s linear 2s;
    opacity: 0;
 
}
.a.animate {
    left :50%;
    opacity: 0;
}
.c.animate {
  
  left: 96%;
  opacity: 1;

}
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   <div class="position: relative;">
       <img alt="a" class="a" src="http://1.bp.blogspot.com/-zp1wNDsbqzc/Tgt-8JzobhI/AAAAAAAAAFs/0DI03F1p8OQ/s1600/hhhfd.gif" style="width: 10%;position: absolute;">
       <div  class="b" src="s" style="width: 10%;position: absolute;height: 100px;width: 100px; background-color: green;z-index: 10;"></div>
       <img alt="c" class="c" src="https://www.jamiesale-cartoonist.com/wp-content/uploads/cartoon-business-man-free1.png" style="width: 10%;position: absolute;">
</div>
<button id="abc" style="margin-top: 50px;">
    Activate
</button>

<script>
$("#abc").on("click", function() {
	$(".a").addClass("animate")
  $(".b").addClass("animate")
  $(".c").addClass("animate")
});
</script>

【讨论】:

猜你喜欢
  • 2021-04-01
  • 1970-01-01
  • 2015-02-02
  • 1970-01-01
  • 2017-09-30
  • 2020-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多