Why isn't this SVG animation working cross-browser? - google-chrome

I have an SVG image generated for me by www.loading.io, and the animation is only working on Google Chrome (v. 48). I have tried opening the file in Internet Explorer 11, Firefox (v. 44), and Edge (v. 25), and they only render the initial image without any animation. Example. You can observe the behavior for yourself as well by downloading the SVG here.
Here is the SVG markup:
<?xml version="1.0" encoding="utf-8"?>
<svg width='50px' height='50px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"
class="uil-ring">
<rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect>
<circle cx="50" cy="50" r="46" stroke-dasharray="145.95839468578177 143.06812944447918" stroke="#285e8c" fill="none"
stroke-width="8">
<animateTransform attributeName="transform" type="rotate" values="0 50 50;180 50 50;360 50 50;"
keyTimes="0;0.5;1" dur=".75s" repeatCount="indefinite" begin="0s"></animateTransform>
</circle>
</svg>
Does anyone know how I can get this nice little SVG to animate on all modern browsers?

The SMIL specification says that durations cannot start with a . character - a leading zero is required and that's what Firefox implements. I've corrected things below so it works in Firefox.
IE does not support SMIL although the fakeSmile library can be used to overcome that.
<?xml version="1.0" encoding="utf-8"?>
<svg width='50px' height='50px' viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"
class="uil-ring">
<rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect>
<circle cx="50" cy="50" r="46" stroke-dasharray="145.95839468578177 143.06812944447918" stroke="#285e8c" fill="none"
stroke-width="8">
<animateTransform attributeName="transform" type="rotate" values="0 50 50;180 50 50;360 50 50;"
keyTimes="0;0.5;1" dur="0.75s" repeatCount="indefinite" begin="0s"></animateTransform>
</circle>
</svg>

Related

Very simple SVG is different between Firefox and Chrome

I have a very simple SVG which gets rendered differently between Firefox and Chrome and I have no idea why. Any suggestions? I would not want to use any CSS to specially style things to get them in sync but have a simple stand-alone SVG.
<?xml version="1.0" encoding="utf-8" ?>
<svg baseProfile="tiny" height="400.0" version="1.2" width="400.0" xmlns="http://www.w3.org/2000/svg">
<rect fill="#fff" fill-opacity="0" stroke="#000" height="90.0" rx="5.0" ry="5.0" stroke-width="3" width="350.0" x="0" y="0"/>
<text font-size="18.0" stroke="#000" text-anchor="start" x="5.0" y="51.0">func: foo_bar_longer</text>
<text font-size="18.0" stroke="#000" text-anchor="end" x="345.0" y="51.0">class: bar_foo_longer</text>
</svg>
Firefox 67 on Linux:
Chromium 75.0.3770.90:
It seems setting font_family="Arial,Helvetica,sans-serif" on all text elements solved the problem. Browsers do not have the same default font.

How can I update several text values inside an SVG Group?

I have an SVG element that is composed of a shape and text. This element is replicated several times inside the SVG file and I wanted to take advantage of the symbol and use tags.
But I need to be able to pass values to update the text nodes inside the symbol as each symbol will have it's own value.
Is there a way to do this without Javascript?
<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 800 800">
<defs>
<g id="Initials">
<circle id="bgColor" cx="200" cy="200" r="80" class="cls-9"/>
<text id="label" fill="white" font-size="50" transform="translate(170, 220)">
10
</text>
</g>
</defs>
<use href="#Initials" />
<use href="#Initials" x="200" y="0" />
</svg>

Starting a SVG animation with keyframes using "begin" property

I'm actually learning SVG in order to import a vector animation I did in Flash inside a website, then integrate some "interactivity" (with the SVG property begin="mouseover").
So first, here is a very simple example of SVG animation I made with the help of the Flash plugin called "Flash2SVG" : https://codepen.io/Rojiraan/pen/owboXr
(StackOverflow want some code when using a Codepen.io link, the problem is that my SVG is way too long, so I did an ultra conversion of my HTML code)
<div class="svg-container">
<svg version="1.1" class="svg-content" viewBox="0 0 550 400" preserveAspectRatio="xMinYMin meet">
<g id="SEQUENCE_No1" overflow="visible">
<g id="THE_RED_RECTANGLE" transform="translate(71 68.05)">
<g>
<g id="Layer11_0_FILL">
<path fill="#F30" stroke="none" d="M408 263.95L408 0 0 0 0 263.95 408 263.95Z"/>
</g>
</g>
</g>
<g display="none">
<g>
<g id="Layer10_0_FILL">
<path fill="#6CF" stroke="none" d="some numbers..."/>
</g>
</g>
<animate attributeName="display" repeatCount="indefinite" dur="3.333s" keyTimes="0;.9;1" values="none;inline;inline"/>
</g>
<g display="none">
<g>
<g id="Layer9_0_FILL">
<path fill="#6CF" stroke="none" d="some numbers..."/>
</g>
</g>
<animate attributeName="display" repeatCount="indefinite" dur="3.333s" keyTimes="0;.8;.9;1" values="none;inline;none;none"/>
</g>
<!-- Et cetera... -->
</svg>
</div>
What I want to do is to start the animation (with the little blue points) when I'm hovering the red rectangle. The thing is I don't really know where to put my "begin" property, I tried various thing without success.
Thanks a lot for reading & for the help !

SVG "use" doesn't show

I have and SVG icon I need to use in a several toolbars on a page.
If I add the SVG code to the location in the toolbar, it works. However, since I need to use it many times I'm trying to define it one at the bottom of the page and then with "use" having it displayed in several places.
So I define it:
<svg>
<defs>
<g id="svgHelp" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none">
<path d="M1 12c0-6.075 4.925-11 11-11s11 4.925 11 11-4.925 11-11 11-11-4.925-11-11z"/>
<path d="M11.792 14v-1c1.609 0 3-1.391 3-3s-1.391-3-3-3c-1.194 0-2.342.893-2.792 1.921"/>
<path d="M12 17v1"/>
</g>
</defs>
</svg>
And then try to use it:
<use xlink:href="#svgHelp" x="0" y="0" />
But it does not display. What am I missing here?
I believe <use> must be wrapped by <svg>
<svg>
<use xlink:href="#svgHelp" x="0" y="0" />
</svg>

Why do markers, patterns, and unicode characters display incorrectly in a svg data uri in google chrome?

I am using google chrome version 24.0.1312.57 on Mac OS X 10.6.8.
In Safari 5.1.7 the svg image looks like this:
In Chrome it looks like this:
Notice the markers are gone from the paths and the path that has a pattern now has a fill of black and the unicode character has an A behind it. This only happens if the image is a data uri in the address bar in google chrome. If I open the svg image up as a file in chrome it displays correctly.
I've tried taking the line endings away and putting it in base64, but it doesn't seem to fix anything.
Is this a bug with chrome or am I missing something?
Here's the source svg:
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg_elem">
<title id="doctitle">URI Test</title>
<defs id="thedefs">
<pattern id="ptrn" overflow="visible" patternUnits="userSpaceOnUse"
x="0" y="0" width="10" height="10"
viewBox="0 0 10 10" >
<line fill="none" stroke="#000000" stroke-width="0.5" x1="-5" y1="-5" x2="15" y2="15"/>
</pattern>
<marker id="mtriangle" viewBox="0 0 10 10" refX="0" refY="5" markerUnits="strokeWidth" markerWidth="4" markerHeight="3" orient="auto">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#FFF" stroke="#000" stroke-width="1"/>
</marker>
<marker id="mcircle" viewBox="-2 -2 12 12" refX="5" refY="5" markerUnits="strokeWidth" markerWidth="4" markerHeight="3" orient="auto">
<circle cx="5" cy="5" r="5" fill="#FFF" stroke="#000" stroke-width="1"/>
</marker>
</defs>
<g>
<path
fill="#F00"
stroke="#000000"
stroke-width="3"
marker-start="url(#mtriangle)"
marker-mid="url(#mcircle)"
d="M10,10l0,60l60,0z"/>
<path
fill="url(#ptrn)"
stroke="#000"
stroke-width="3"
marker-start="url(#mtriangle)"
marker-mid="url(#mcircle)"
d="M110,110l0,70l70,0z"/>
<text
fill="#000"
x='100'
y='100'
font-size="14pt"
font-family="serif"
text-anchor="middle"
space="preserve">N 34° 45' 30" E 300 ft</text>
</g>
</svg>
Here's the data uri.
data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODUwIiBoZWlnaHQ9IjEwNTAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIGlkPSJzdmdfZWxlbSI+PHRpdGxlIGlkPSJkb2N0aXRsZSI+VVJJIFRlc3Q8L3RpdGxlPjxkZWZzIGlkPSJ0aGVkZWZzIj4gICAgPHBhdHRlcm4gaWQ9InB0cm4iIG92ZXJmbG93PSJ2aXNpYmxlIiBwYXR0ZXJuVW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4PSIwIiB5PSIwIiB3aWR0aD0iMTAiIGhlaWdodD0iMTAiIHZpZXdCb3g9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cm9rZT0iIzAwMCIgc3Ryb2tlLXdpZHRoPSIzIiBtYXJrZXItc3RhcnQ9InVybCgjbXRyaWFuZ2xlKSIgbWFya2VyLW1pZD0idXJsKCNtY2lyY2xlKSIgZD0iTTExMCwxMTBsMCw3MGw3MCwweiI+PC9wYXRoPiAgICAgICAgICAgICAgPHRleHQgZmlsbD0iIzAwMCIgeD0iMTAwIiB5PSIxMDAiIGZvbnQtc2l6ZT0iMTRwdCIgZm9udC1mYW1pbHk9InNlcmlmIiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBzcGFjZT0icHJlc2VydmUiPk4gMzTCsCA0NScgMzAiIEUgMzAwIGZ0PC90ZXh0PjwvZz48L3N2Zz4JCQk=
Not sure about markers and patterns, but as for the character set, Chrome must be using a different default encoding for data:URIs. If you add charset=UTF-8; in the beginning, e.g.:
data:image/svg+xml;charset=UTF-8;base64,PHN2ZyB3aWR0aD0iODUwIiBoZWlnaHQ9IjEwNTAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIGlkPSJzdmdfZWxlbSI+PHRpdGxlIGlkPSJkb2N0aXRsZSI+VVJJIFRlc3Q8L3RpdGxlPjxkZWZzIGlkPSJ0aGVkZWZzIj4gICAgPHBhdHRlcm4gaWQ9InB0cm4iIG92ZXJmbG93PSJ2aXNpYmxlIiBwYXR0ZXJuVW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4PSIwIiB5PSIwIiB3aWR0aD0iMTAiIGhlaWdodD0iMTAiIHZpZXdCb3g9IjAgMCAxMCAxMCI+ICAgICAgICA8bGluZSBmaWxsPSJub25lIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iMC41IiB4MT0iLTUiIHkxPSItNSIgeDI9IjE1IiB5Mj0iMTUiPjwvbGluZT4gICAgPC9wYXR0ZXJuPiAgICA8bWFya2VyIGlkPSJtdHJpYW5n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IgeD0iMTAwIiB5PSIxMDAiIGZvbnQtc2l6ZT0iMTRwdCIgZm9udC1mYW1pbHk9InNlcmlmIiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBzcGFjZT0icHJlc2VydmUiPk4gMzTCsCA0NScgMzAiIEUgMzAwIGZ0PC90ZXh0PjwvZz48L3N2Zz4JCQk=
...it should work properly!
Here's a fiddle.
EDIT Upon further inspection (re: markers and patterns), it seems like this is a bug in Chrome. It looks like Chrome incorrectly interprets (completely ignores?) url(#hash) attribute values in SVG data:URIs when embedded as <object> (and possibly in other cases?).
Here's another fiddle with extensive testing of this issue.
Everything works correctly for me in Safari 6.0.2, Firefox 18.0.2 (Mac), Firefox 10.0.1 (Win), Opera 12.12 (Mac), and IE 9. <object> (as well as <embed> and <iframe>) embeds are not displaying correctly in Chrome 24.0.1312.57 (Mac/Win) or 26.0.1405.0 canary (Mac), whereas <img> embeds are working fine. Pasting either the URI-encoded or base64-encoded data:URIs into the address bar is also not working.