CSS translates SVG group with percent

Currently, I seem to be able to apply translate and translate3d in a group inside SVG using px but not using percentages. I am wondering if% can be used at all? The reason I need them is because I want to animate the contents of several SVGs through CSS. (Using a JS library like snap or svgjs gives me a whole bunch of other headaches, such as scaling issues in Chrome, so I'd rather not use them.)

I created a fiddle to illustrate the behavior: http://jsfiddle.net/f4MU3/4/

CSS

.cloud-svg .group { -webkit-transform:translate3d(50%,50%,0); -moz-transform:translate3d(50%,50%,0); transform:translate3d(50%,50%,0); } 

HTML:

 <div class="container"> <div class="cloud"> <svg class="cloud-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 107.4 50.6" enable-background="new 0 0 107.4 50.6" xml:space="preserve" preserveAspectRatio="xMinYMin meet" width="100%" height="100%"> <svg x="0%" y="0%" viewBox="0 0 107.4 50.6"> <g class="group"> <path d="M74.6 20.6c3.4-5.3 8.5-7.2 14.1-7.9c4.3-0.6 8.7-0.3 12.8 1.7c1.9 0.9 3.2 2.2 3.8 4.1 c0.8 3.1 1.8 6.2 1.9 9.5c0.1 5.8-0.6 11.5 0.2 17.3c0.4 2.8-0.5 3.5-3.3 3.5c-5.2-0.1-10.3-0.5-15.5-0.8c-0.6 0-1.3-0.1-1.9-0.3 c-2-0.9-2.7 3.8-5.2 0.9c-1.7-1.9-4.3-1-6.5-1c-2.1 0.1-4.7 0.2-6.1-0.4c-6.5-3-12.8-0.4-19.1-0.4c-3.9 0-7.7 0.1-11.5-0.9 c-2.9-0.7-5.8-0.2-8.6 0.5c-8.3 2.3-16.7 3.3-25.3 4.1c-2.6 0.2-3.9-0.8-4.1-3.5c-0.2-2.6-0.1-5.2 0.6-7.7 C3.2 30.2 7.6 21.9 14 14.9c4.2-4.6 10.2-5.8 16.3-6.1c1.9-0.1 3.1 1.6 4.6 2.5c1.5 1 2.7 1.5 3.8-0.6c2.3-4.4 6-7.1 10.9-8.2 c1.6-0.3 3.1-1 4.5-1.7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for animation.)

Oddly enough, I sometimes saw that it works with percentages in Chrome and Safari, but not in Firefox. It seems he cannot recreate it, though.

+6
source share
1 answer

How it sometimes works in Chrome / Safari - I think this is due to a bug in Webkit / Blink, which for some time imposed on developers. For some reason, the translation is not performed initially, but if you, for example, adjust the values ​​in the developer panel, you can see that the cloud is being translated as you expected.

You can also make it visualize by dynamically changing the style using JavaScript after a trivial timeout (0 ms). For example, if you completely remove the CSS rule and do this, it works:

Demo link

 function fix() { var e = document.querySelector(".group"); e.style.transform = "translate3d(50%,50%,0)"; } setTimeout(fix, 0) 

This is not an ideal solution, but other solutions do not seem to work for me. Unfortunately, this also does not help Firefox, but perhaps it will help in the solution.

+1
source

All Articles