用css将一个矩形做成半心形的动画。

问题描述 投票:0回答:1

该动画先将形状向下移动,然后再向左移动,而不是对角线移动。我是在动画时间上出了问题,或者是元素的定位上出了问题.我明白这只是动画形状,这在很多帖子中已经介绍过了。我发现用伪元素来制作形状的动画很棘手。感谢大家的帮助。

.container {
  background-color: black;
  height: 500px;
  width: 300px;
  margin: 0 auto;
  position: relative;
}

.firsthalf
/* this is going to turn into the bottom of the half heart shape */

{
  height: 0px;
  width: 0px;
  position: absolute;
  margin: auto;
  right: 0px;
  top: 25px;
  border: 25px solid green;
  animation-name: heart-bottom1;
  animation-duration: 3s;
}

@keyframes heart-bottom1 {
  0% {
    top: 25px;
    right: 0px;
    border-radius: 25px solid green;
  }
  50% {
    border-bottom: 25px solid transparent;
    border-right: 25px solid transparent;
    top: 200px;
    left: 100px;
  }
  100% {
    top: 25px;
    right: 0px;
  }
}

.firsthalf::before
/*this is going to turn into the upper part(the spherical bit) of the half 
      heart*/

{
  content: "";
  background-color: green;
  height: 25px;
  width: 50px;
  position: absolute;
  bottom: 25px;
  left: -25px;
  animation-name: heart-up1;
  animation-duration: 3s;
}

@keyframes heart-up1 {
  0% {
    height: 25px;
    width: 50px;
    border-radius: 0;
  }
  50% {
    border-radius: 25px 25px 0 0;
  }
  100% {
    border-radius: 0;
    height: 25px;
    width: 50px;
  }
}
<div class="container">
  <div class="firsthalf">
  </div>
</div>
html css css-animations pseudo-element css-shapes
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.