单击触发器时不保留完整动画



我正在用一个按钮触发一个svg标记。我这样做的方法是将复选标记设置为 opacity:0;,然后单击按钮后,添加一个类fadeIn并将不透明度设置为opacity:1;

我的问题是当不透明度设置为 0 时,动画会发生变化。未显示完整动画。您可以通过将opacity:0从chechmark类中取出并再次运行小提琴来看到这一点。

我的问题是,如何在保持完整动画序列的同时让这个复选标记与按钮一起触发/显示。

这是一个小提琴。代码段未生成复选标记,不知道原因。

$('#trigger').on('click', function () {
	$('.checkmark').addClass('fadeIn');
});
.checkmark {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  display: block;
  stroke-width: 5;
  stroke: #fff;
  stroke-miterlimit: 10;
  margin: 10% auto;
  box-shadow: inset 0px 0px 0px #0783a7;
  animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
  opacity: 0;
  z-index: 2;
}
.checkmark-circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  stroke-width: 5;
  stroke-miterlimit: 10;
  stroke: #0783a7;
  fill: none;
  animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark-check {
  transform-origin: 50% 50%;
  stroke-dasharray: 70;
  stroke-dashoffset: 70;
  animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
@keyframes stroke {
  100% {
    stroke-dashoffset: 0;
  }
}
@keyframes scale {
  0%, 100% {
    transform: none;
  }
  50% {
    transform: scale3d(1.1, 1.1, 1);
  }
}
@keyframes fill {
  100% {
    box-shadow: inset 0px 0px 0px 100px #0783a7;
  }
}
.fadeIn {
    opacity: 1;
    transition: all 0.8s ease;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="trigger">Trigger</button>
<div id="wrap">
  <div id="checkmark-text">All Templates Selected</div>
  <svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
    <circle class="checkmark-circle" cx="26" cy="26" r="25" fill="none"/>
    <path class="checkmark-check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
  </svg>
</div>

可以通过根据

.fadeIn类的添加对所需元素运行animation规则来解决此问题,而不是将其放置在元素加载时具有的类上。试试这个:

.checkmark {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    display: block;
    stroke-width: 5;
    stroke: #fff;
    stroke-miterlimit: 10;
    margin: 10% auto;
    box-shadow: inset 0px 0px 0px #0783a7;
    z-index: 2;
    opacity: 0;
}
.checkmark-circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 5;
    stroke-miterlimit: 10;
    stroke: #0783a7;
    fill: none;
}
.checkmark-check {
    transform-origin: 50% 50%;
    stroke-dasharray: 70;
    stroke-dashoffset: 70;
}
.checkmark.fadeIn {
    opacity: 1;
    transition: all 0.8s ease;
    animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark.fadeIn .checkmark-circle {
    animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark.fadeIn .checkmark-check {
    animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
@keyframes stroke {
    100% {
        stroke-dashoffset: 0;
    }
}
@keyframes scale {
    0%,
    100% {
        transform: none;
    }
    50% {
        transform: scale3d(1.1, 1.1, 1);
    }
}
@keyframes fill {
    100% {
        box-shadow: inset 0px 0px 0px 100px #0783a7;
    }
}

更新的小提琴