SVG reverse drawing css animation cross-browsers - html

I'm fighting with CSS SVG animations and I found the problem which I cannot overcome. My animation works properly in Chrome, Opera and Firefox but Safari has a problem with it - inside circles should draw itself anticlockwise.
Anyone know how to solve this?
Thanks!
.padding {
padding-left: 20px;
padding-right: 20px;
background-color: grey;
}
svg .cog-one,
svg .cog-two {
stroke-dasharray: 390;
stroke-dashoffset: 390;
transition: all 1s linear;
}
svg .circle-one {
stroke-dasharray: 100%;
stroke-dashoffset: -100%;
transition: all .6s linear .3s;
}
svg .cog-two {
transition-delay: .3s;
}
svg .circle-two {
stroke-dasharray: 100%;
stroke-dashoffset: -100%;
transition: all .6s linear .6s;
}
svg:hover .cog-one,
svg:hover .cog-two {
stroke-dashoffset: 0;
}
svg:hover .circle-two {
stroke-dashoffset: 0%;
}
svg:hover .circle-one {
stroke-dashoffset: 0%;
}
<svg width="250" height="250" viewbox="0 0 162.95 117.37" class="padding">
<path fill="none" stroke="#231f20" stroke-width="5.5" d="M2331.44,513.63a0.3,0.3,0,0,1-.4,0l-9.58-7.17-1.23.61a35.5,35.5,0,0,1-4.16,1.73l-1.3.44-1.7,11.91a0.31,0.31,0,0,1-.09.18,0.32,0.32,0,0,1-.23.09h-16.1a0.32,0.32,0,0,1-.33-0.26l-1.73-11.87-1.29-.44a35.49,35.49,0,0,1-4.19-1.68l-1.24-.61-9.69,7.29a1.23,1.23,0,0,1-.63.19l-11.34-11.32a0.9,0.9,0,0,1,.14-0.68l7.4-9.8-0.61-1.24a35.42,35.42,0,0,1-1.73-4.15l-0.45-1.3-11.91-1.69a0.32,0.32,0,0,1-.27-0.31V467.49a0.31,0.31,0,0,1,.09-0.23,0.31,0.31,0,0,1,.18-0.09l11.89-1.7,0.44-1.3a35.2,35.2,0,0,1,1.72-4.15l0.61-1.23-7.21-9.6a0.35,0.35,0,0,1,0-.44l11.38-11.38a0.35,0.35,0,0,1,.43,0l9.62,7.22,1.21-.59a35.09,35.09,0,0,1,4.18-1.74l1.3-.44,1.69-11.9a0.31,0.31,0,0,1,.09-0.18,0.32,0.32,0,0,1,.23-0.09h16.1a0.31,0.31,0,0,1,.31.27l1.71,11.89,1.3,0.44a35.08,35.08,0,0,1,4.18,1.7l1.23,0.6,9.65-7.25a0.45,0.45,0,0,1,.49,0L2343,448.59a0.46,0.46,0,0,1,0,.49l-7.29,9.69,0.61,1.23a35.49,35.49,0,0,1,1.72,4.16l0.44,1.3,11.9,1.7a0.31,0.31,0,0,1,.27.31v16.1a0.32,0.32,0,0,1-.09.22,0.31,0.31,0,0,1-.18.09l-11.9,1.7-0.44,1.3a35.25,35.25,0,0,1-1.73,4.15l-0.61,1.23,7.19,9.59a0.3,0.3,0,0,1,0,.4Z" transform="translate(-2256.03 -406.85)" class="cog-one"></path>
<circle fill="none" stroke="#231f20" stroke-width="2.75" cx="48.67" cy="68.69" r="20.8" class="circle-one"></circle>
<path fill="none" stroke="#231f20" stroke-width="5.5" d="M2411.82,460.56a0.22,0.22,0,0,1-.25.14l-8.39-2.1-0.65.75a25.64,25.64,0,0,1-2.29,2.31l-0.74.66,2.2,8.41a0.22,0.22,0,0,1,0,.14,0.23,0.23,0,0,1-.12.13l-10.74,4.52a0.22,0.22,0,0,1-.28-0.09l-4.47-7.42-1,.07a25.64,25.64,0,0,1-3.26,0l-1-.06-4.41,7.56a0.89,0.89,0,0,1-.37.3l-10.72-4.37a0.65,0.65,0,0,1-.1-0.49l2.19-8.6-0.75-.65a25.59,25.59,0,0,1-2.31-2.28l-0.66-.74-8.4,2.2a0.23,0.23,0,0,1-.27-0.13l-4.5-10.72a0.23,0.23,0,0,1,0-.18,0.22,0.22,0,0,1,.09-0.11l7.45-4.46-0.07-1a25.43,25.43,0,0,1,0-3.25l0.06-1-7.49-4.38a0.25,0.25,0,0,1-.12-0.29l4.4-10.76a0.25,0.25,0,0,1,.29-0.13l8.43,2.12,0.64-.73a25.35,25.35,0,0,1,2.3-2.33l0.74-.66-2.2-8.4a0.23,0.23,0,0,1,0-.15,0.23,0.23,0,0,1,.12-0.13l10.72-4.51a0.23,0.23,0,0,1,.28.09l4.46,7.44,1-.07a25.34,25.34,0,0,1,3.26,0l1,0.06,4.4-7.53a0.33,0.33,0,0,1,.31-0.17l10.76,4.4a0.33,0.33,0,0,1,.11.34l-2.15,8.49,0.75,0.65a25.64,25.64,0,0,1,2.31,2.29l0.66,0.74,8.4-2.19a0.23,0.23,0,0,1,.27.13l4.5,10.72a0.23,0.23,0,0,1,0,.18,0.23,0.23,0,0,1-.09.11l-7.45,4.46,0.07,1a25.46,25.46,0,0,1,0,3.25l-0.06,1,7.47,4.38a0.22,0.22,0,0,1,.08.28Z" transform="translate(-2256.03 -406.85)" class="cog-two"></path>
<circle fill="none" stroke="#231f20" stroke-width="2.75" cx="2383.36" cy="442.66" r="14.33" transform="translate(-2241.52 550.51) rotate(-22.78)" class="circle-two"></circle>
</svg>

If Safari is drawing the circle the wrong direction, then that will be a bug in Safari. The SVG spec is clear on which direction strokes are meant to go. You may wish to report that bug to Apple.
The way to resolve your immediate problem would be to convert your <circle> elements to <path> elements. That way you control the path direction.

Related

How to implement animation on stroke-dasharray and stroke-offset circle svg?

I try to make piechart using stroke line, however isn't work. The idea is piechart will be animate from 0 to 50 line.
#circle{
stroke-dasharray: 50 100;
stroke-dashoffset: 0;
fill: none;
stroke: black;
stroke-width: 5px;
transition: 0.3s;
animation: progress 5s linear forwards;
#keyframes progress {
from {
stroke-dasharray: 0 100;
stroke-dashoffset: 0;
}
to {
stroke-dasharray: 50 100;
stroke-dashoffset: 50;
}
}
}
<svg >
<circle cx='24' cy='24' r='18' id="circle"/>
</svg>
The keyframes at-rule is not part of the CSS selector for the element. As default the path of the circle starts at 3 o'clock. The total length of the circle path can be controlled using the attribute pathLength. If the animation should go clockwise I think is is easier to control the starting point by setting the transform/rotate attribute on the circle instead of using the dasharray offset.
#circle {
stroke-dasharray: 0 100;
fill: none;
stroke: black;
stroke-width: 5px;
animation: progress 5s linear forwards;
}
#keyframes progress {
from {
stroke-dasharray: 0 100;
}
to {
stroke-dasharray: 100 100;
}
}
<svg>
<circle cx='24' cy='24' r='18' id="circle"
pathLength="100" transform="rotate(-90 24 24)"/>
</svg>

HTML SVG reduce circle size

I have found animated circle made with svg but I need to reduce the circle size
How can I modify the code please?
#keyframes dash {
from {
stroke-dashoffset: 816;
}
to {
stroke-dashoffset: 0;
}
}
.progress-circle path {
stroke-dasharray: 816;
stroke-dashoffset: 0;
animation: dash 2s linear;
animation-delay: 0.3s;
}
<svg class="progress-circle" width="70" height="70">
<path
d="m35,2.5c17.955803,0 32.5,14.544199 32.5,32.5c0,17.955803 -14.544197,32.5 -32.5,32.5c-17.955803,0 -32.5,-14.544197 -32.5,-32.5c0,-17.955801 14.544197,-32.5 32.5,-32.5z"
stroke="#000" stroke-width="1" fill="transparent" />
</svg>
You need to change the width and height and then add the viewbox atrribute with the original size:
#keyframes dash {
from {
stroke-dashoffset: 816;
}
to {
stroke-dashoffset: 0;
}
}
.progress-circle path {
stroke-dasharray: 816;
stroke-dashoffset: 0;
animation: dash 2s linear;
animation-delay: 0.3s;
}
<svg class="progress-circle" width="30" height="30" viewBox="0 0 70 70">
<path
d="m35,2.5c17.955803,0 32.5,14.544199 32.5,32.5c0,17.955803 -14.544197,32.5 -32.5,32.5c-17.955803,0 -32.5,-14.544197 -32.5,-32.5c0,-17.955801 14.544197,-32.5 32.5,-32.5z"
stroke="#000" stroke-width="1" fill="transparent" />
</svg>
add viewBox= "0 0 50 50" in svg tag and reduce svgwidth and height

SVG arrow wrong sync animation

why doesn't the arrow start along with the line?
Is it not synchronized?
I would like the arrow to leave together with the line.
.box{
width:100%;
padding:0px;
background-color: black;
}
.squiggle {
stroke-dasharray: 498.181;
stroke-dashoffset: 498.181;
animation: draw 10s linear infinite;
}
#keyframes draw {
from {
stroke-dashoffset: 498.181;
}
to {
stroke-dashoffset: 0;
}
}
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=5">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<body>
<div class="box">
<svg xmlns="http://www.w3.org/2000/svg" id="svg1" viewBox="0 0 215 66" preserveAspectRatio="xMidYMid meet">
<g id="layer1" transform="translate(-68.19229,10.180375)">
<g id="g38" transform="matrix(0.26458333,0,0,0.26458333,54.727655,-107.07271)">
<g>
<path id="path22" class="squiggle"
style="fill:none;
stroke:orange;
stroke-width:3px;
stroke-linecap:butt;
stroke-linejoin:miter;
stroke-opacity:1"
d="M 653.40952,459.58095 C 539.70759,242.15840999999995 379.43686,703.6978899999999 252.34286,526.62857"/>
<use href="#path22"/>
<path fill="red" d="M -9.5357143,-9.9107143 10,0 -10,10 -3.3928571,-0.17857143 Z">
<animateMotion dur="10s" repeatCount="indefinite" rotate="auto">
<mpath href="#path22"/>
</animateMotion>
</path>
</g>
</g>
</g>
</svg>
</div>
</body>
</html>
look at this, This may be helpful:
#desc {
max-width: 700px;
margin-top: 100px;
color: #b3b3b3;
font-size: 11px;
font-family: sans-serif;
}
#desc li {
margin-bottom: 1em;
}
#desc p {
padding: 20px 0 0 40px;
}
#doubled-separate {
width: 110px;
}
#doubled-separate #over-path {
fill: none;
stroke-dasharray: 150;
stroke-dashoffset: 0;
animation: 10s reveal linear infinite forwards;
}
#keyframes reveal {
50%, 100% {
stroke-dashoffset: 150;
}
}
#separate-marker {
width: 88px;
position: relative;
top:-4px;
}
#separate-marker .just-line {
fill: none;
stroke-dashoffset: 0;
animation: 10s reveal2 linear infinite forwards;
}
#keyframes reveal2 {
100% {
stroke-dashoffset: 150;
}
}
#doubled-separate-marker {
width: 110px;
}
#doubled-separate-marker .over-path {
fill: none;
stroke-dasharray: 150;
stroke-dashoffset: 0;
animation: 3s reveal3 linear infinite forwards;
}
#keyframes reveal3 {
50%, 100% {
stroke-dashoffset: 150;
}
}
#doubled-separate-marker-2 {
width: 110px;
}
#doubled-separate-marker-2 #arrow3 path {
opacity: 0;
animation: 10s revealarrow linear infinite forwards;
}
#keyframes revealarrow {
0%, 50% {
opacity: 0;
}
60%, 100% {
opacity: 1;
}
}
#doubled-separate-marker-2 .over-path {
fill: none;
stroke-dasharray: 150;
stroke-dashoffset: 0;
animation: 10s reveal4 linear infinite forwards;
}
#keyframes reveal4 {
50%, 100% {
stroke-dashoffset: 150;
}
}
#separate-marker-2 {
width: 88px;
position: relative;
top:-4px;
}
<svg viewBox="0 0 44 97" preserveAspectRatio="xMinYMin meet" id="separate-marker-2">
<defs>
<marker id="arrow4" viewBox="0 0 13 13" refX="11" refY="8" markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto-start-reverse" preserveAspectRatio="xMinYMin meet">
<path d="M3.66332316,0.125850427 L3.75090984,0.194245468 L12.2529105,7.89856961 C12.6592041,8.26674392 12.5414228,8.91869993 12.063138,9.1358919 L11.9627228,9.17332054 L0.963626457,12.4383634 C0.566538833,12.5562375 0.149079906,12.3298902 0.0312058479,11.9328025 C-0.0768453724,11.5688056 0.10434498,11.187691 0.441152309,11.0359066 L0.536766731,11.0003819 L10.2568836,8.11360225 L2.74367477,1.30576583 C2.46464034,1.05291103 2.41998014,0.63794112 2.62313708,0.333974789 L2.69153212,0.246388115 C2.94438692,-0.0326463148 3.35935683,-0.0773065179 3.66332316,0.125850427 L3.66332316,0.125850427 Z" fill="#B3B3B3" fill-rule="nonzero"></path>
</marker>
</defs>
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(1.000000, 1.000000)">
<path d="M31.6194299,0 C-0.925516514,8.99255645 -7.90071768,47.4229255 8.63466801,71.535115 C9.41568622,72.6740094 10.2491558,73.7809605 11.1348599,74.8513572" class="just-line" stroke="#B3B3B3" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4" marker-end="url(#arrow4)">
<animate attributeName="d" from="M31.6194299,0 C-0.925516514,8.99255645 -7.90071768,47.4229255 8.63466801,71.535115 C9.41568622,72.6740094 10.2491558,73.7809605 11.1348599,74.8513572" to="M31.6194299,0 C-0.925516514,8.99255645 -7.90071768,47.4229255 8.63466801,71.535115 C15.4626235,81.4917594 26.2993953,89.006995 41,91" dur="1.5s" repeatCount="indefinite"/>
</path>
</g>
</g>
</svg>
<div id="desc">
<ol>
<li>Line and arrowhead are two paths grouped together, with an identical (but wide and white) line path on top that animates to reveal.</li>
<li>Line path with arrowhead path attached as a marker. dash-offset animates on line path to add movement.</li>
<li>Fusion of 1 and 2. Line path with arrowhead as marker, white line path animating on top. Shows that path+marker connection is much smoother than path+path, and that butt linecaps create a smoother animation finish than square or round (although it required moving the white path start-point a step or two to cover the marker).</li>
<!-- figuring out CSS animation on an SVG marker was a JOURNEY -->
<li>Adaptation of 3. The arrowhead SVG marker has CSS animation applied. Since it doesn't appear until after the line path is fully visible, the white line path on top has a narrower stroke since it doesn't need to cover the marker. The animation timings are synced up via keyframe percentages.</li>
<li>native SVG animate!</li>
</ol>
<p>DISCLAIMER: honestly no idea about browser support for any of this</p>
</div>

Animating SVG icon on hover

I'm attempting to animate an SVG line icon ONLY on hover. I'd like it to be static when not hovered. I've worked out how to animate the drawing effect, and I can get it kind of working on hover.. however when it's going between the 'from' and 'to' keyframes, the dashes get smaller and it doesn't create the smooth drawing effect I was hoping for. I am doing this purely HTML/CSS.
.bell_line:hover {
animation: draw 3s linear forwards;
}
#keyframes draw {
from {
stroke-dashoffset:92;
stroke-dasharray: 92;
}
to {
stroke-dashoffset:0;
stroke-dasharray: 0;
}
}
<div class="bell_line" style="margin-left: 100px;margin-top: 100px;">
<svg class="bell_line" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60.85 38.83">
<g data-name="bell_line" fill="none" stroke="#000" stroke-linecap="round" stroke-miterlimit="10">
<path class="bell_line" d="M18.43 28.41l5.38-14.11v-3a5.62 5.62 0 0111.23 0v3l5.33 14.11zM29.38 5.67V.5M29.38 33.2v5.13"/>
</g>
</svg>
</div>
Would transition solve your issue? I usually find it a simpler solution for hover states.
Your css would end up looking like this,
.bell_line {
fill: none;
stroke: black;
stroke-dashoffset: 0;
stroke-dasharray: 0;
transition: stroke-dashoffset 2s ease;
}
.bell_line:hover {
stroke-dashoffset: 92;
}
OR if you want to animate two states (in your case draw off draw on) you will need to create an animation that draws off the dashoffet by its halfway point, then redraws it by it's completion.
Like so,
#keyframes draw {
0% {
stroke-dashoffset: 0;
}
50% {
stroke-dashoffset: 90;
}
100% {
stroke-dashoffset: 180;
}
}
.bell_line {
fill: none;
stroke: black;
stroke-dashoffset: 0;
stroke-dasharray: 90;
}
.bell_line:hover {
animation: draw 2s linear forwards;
}
Here we only animate the dashoffset to produce the animation effect then reset the
Here's a working example,
https://stackblitz.com/edit/react-bell-line
https://react-bell-line.stackblitz.io
Also just be mindful that the hover state is on the path. You could always make the hover state on the svg then point to the path.
svg:hover > .bell_line
This would just mean you can create a larger area to target with the mouse.

SVG line animation

I am trying to use this trick to animate an svg picture:
http://css-tricks.com/svg-line-animation-works/
Here I created a codepen with my own version, but no matter what I do I can't seem to make it work. As far as I can see the only difference between my version and the one on css tricks is that I am using line elements instead of paths.
http://codepen.io/webconsult/pen/HgIsk
Additionally, can someone tell me how to accomplish this without using an inline svg?
CSS:
svg {
width: 100%;
}
svg .line {
stroke-dasharray: 1300;
animation: dash 5s linear alternate infinite;
}
#keyframes dash {
from {
stroke-dashoffset: 1300;
}
to {
stroke-dashoffset: 0;
}
}
SVG:
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="1920px" height="640px" viewBox="0 0 1920 640" enable-background="new 0 0 1920 640" xml:space="preserve">
<line class="line" fill="none" stroke="#8FB6D0" stroke-miterlimit="10" x1="640" y1="482" x2="-1" y2="482"/>
<line class="line" fill="none" stroke="#8FB6D0" stroke-miterlimit="10" x1="640" y1="482" x2="-1" y2="482"/>
[...]
<line class="line" fill="none" stroke="#8FB6D0" stroke-miterlimit="10" x1="640" y1="482" x2="-1" y2="482"/>
</svg>
On chrome (or other), css animation needs to be written with vender prefix yet.
So, you should rewrite the code like this.
svg {
width: 100%;
}
svg .line {
stroke-dasharray: 1300;
animation: dash 5s linear alternate infinite;
-webkit-animation: dash 5s linear alternate infinite;
}
#keyframes dash {
from {
stroke-dashoffset: 1300;
}
to {
stroke-dashoffset: 0;
}
}
#-webkit-keyframes dash {
from {
stroke-dashoffset: 1300;
}
to {
stroke-dashoffset: 0;
}
}