stroke-dashoffset doesnt work for me

2.1k views Asked by At

While working with animating svg i discovered strange issue that stroke-dashoffset doesnt work for me. I want to make acheckmark to draw itself.

I created a pen so you can watch it here: https://codepen.io/kalreg/pen/yorQaV

<svg>
  <path stroke="red" fill="none" stroke-width=10 stroke-dashoffset=6530  d="M5,50 L60,105 L150,5"></path>
</svg>

Both changing css or attribute of path from negative, through 0 to positive values doesnt change appearance of checkmark

I am not sure what am i doing wrong, so any advice would be more than appreciated. Thank you.

1

There are 1 answers

1
Dekel On BEST ANSWER

The animation of stroke-dashoffset works together with stroke-dasharray and you are also missing the @keyframes to actual have the animation:

path {
  stroke-dasharray: 6630;
  stroke-dashoffset: 6630;
  animation: dash 5s linear forwards;
}

@keyframes dash {
  to {
    stroke-dashoffset: 0;
  }
}

Here is the update to your codepen:
https://codepen.io/anon/pen/mMgQMY