用css动画[关闭]

问题描述 投票:-4回答:2

我想将我的左侧物体移动到红色框然后隐藏它,然后我想在红色框附近显示正确的物体,然后该物体也将从红色框移动到页面的右侧。这该怎么做?有关解释 - 请单击此处Image Link

javascript html css
2个回答
1
投票

尝试使用此类转换延迟的转换属性

欲了解更多信息,请阅读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>

3
投票

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

.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>
© www.soinside.com 2019 - 2024. All rights reserved.