Home > database >  Increase Size of SVG Animation
Increase Size of SVG Animation

Time:07-09

I'm using this CSS checkmark animation I found for a success page. It works well, but a bit small. I'd like to increase it in size to about 300 pixels.

I tried increasing the viewBox size to 300, but it didn't work:

<svg  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300">
  <circle  cx="26" cy="26" r="25" fill="none"/>
  <path  fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>

What is the correct way to increase the size?

.checkmark__circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  stroke-width: 2;
  stroke-miterlimit: 10;
  stroke: #7ac142;
  fill: none;
  animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: block;
  stroke-width: 2;
  stroke: #fff;
  stroke-miterlimit: 10;
  margin: 10% auto;
  box-shadow: inset 0px 0px 0px #7ac142;
  animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}

.checkmark__check {
  transform-origin: 50% 50%;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  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 30px #7ac142;
  }
}
<svg  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
  <circle  cx="26" cy="26" r="25" fill="none"/>
  <path  fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>

CodePudding user response:

I've left three comments below indicating the sizes you need to increase, all in CSS:

  1. The SVG width
  2. The SVG height
  3. The shadow "fill" in the animation (set to 50% the size of the width/height)

.checkmark__circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  stroke-width: 2;
  stroke-miterlimit: 10;
  stroke: #7ac142;
  fill: none;
  animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark {
  width: 200px;  /* 1. change the width here */
  height: 200px; /* 2. change the height here */
  border-radius: 50%;
  display: block;
  stroke-width: 2;
  stroke: #fff;
  stroke-miterlimit: 10;
  margin: 10% auto;
  box-shadow: inset 0px 0px 0px #7ac142;
  animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}

.checkmark__check {
  transform-origin: 50% 50%;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  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% {
    /* 3. change the shadow spread-radius here to 50% the width/height */
    box-shadow: inset 0px 0px 0px 100px #7ac142; 
  }
}
<svg  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
  <circle  cx="26" cy="26" r="25" fill="none"/>
  <path  fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>

  • Related