Answer the question
In order to leave comments, you need to log in
What library can be used to animate SVG?
The site has a lot of svg icons (for example, 6-12 icons on each page). They are inserted through the img tag. It is necessary that when hovering over the svg block, the icon is randomly drawn. I thought to use lazylinepainter, but there you need to enter each svg into js code, this will not be very convenient. Perhaps there is an easier way to make such an animation.
Answer the question
In order to leave comments, you need to log in
Raphael is quite old, Dmitry Baranovsky has a new library
: snapsvg.io/about
inside an img, the SVG is only styled within the svg tag and cannot be targeted via img:hover.
If it's not a secret, why exactly img? If included directly as svg, you can do without a whole separate library. It is possible to write an animation in vanilla CSS for the path in the icon. For example, if :<svg class="icon">
.icon path {
stroke-dasharray: 123123;
stroke-dashoffset: 123123;
animation: draw forwards;
}
@keyframes draw {
to {
stroke-dashoffset: 0;
}
}
const path = Array.from(document.querySelectorAll(".icon path"));
let length = 0;
const ls = path.map(p => {
length = p.getTotalLength();
p.style.strokeDasharray = length;
p.style.strokeDashoffset = length;
return length;
});
They are inserted through the img tag.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question