CSS-transform in Edge not working as intended - html

I have an svg illustration of a drone and I want the propellers to be rotating. The animation works perfectly fine in Chrome and Firefox but in Edge the rotation center is weird. It probably has to do with the transform-origin: center property but I have no idea how to correct it because it does work in Firefox/Chrome.
.drone .body {
fill: #000000;
}
.drone .wing {
fill: #000000;
animation: wing 5s linear forwards infinite;
transform-box: fill-box;
transform-origin: center;
}
#keyframes wing {
100% {
transform: rotateY(7200deg);
}
}
<svg id="drone1" class="drone" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1923 643" preserveAspectRatio="xMinYMin meet">
<g id="drone1-droneContainer">
<g class="wing left">
<path d="M13,2c-0.6,0-1-0.4-1-1s0.4-1,1-1s8,0.4,8,1S13.6,2,13,2z"/>
<path d="M8,2C7.4,2,0,1.6,0,1s7.4-1,8-1s1,0.4,1,1S8.6,2,8,2z"/>
</g>
<g class="wing right">
<path d="M48,2c-0.6,0-1-0.4-1-1s0.4-1,1-1s8,0.4,8,1S48.6,2,48,2z"/>
<path d="M43,2c-0.6,0-8-0.4-8-1s7.4-1,8-1s1,0.4,1,1S43.6,2,43,2z"/>
</g>
<g class="body">
<path d="M45,0.5C45,0.2,45.2,0,45.5,0S46,0.2,46,0.5V4c0.6,0,1,0.4,1,1v1h0.5C48.3,6,49,6.7,49,7.5S48.3,9,47.5,9H37v0.9
c0,0.7-0.4,1.4-1,1.7l-3.6,2.1c-0.3,0.2-0.7,0.3-1,0.3h-6.9c-0.4,0-0.7-0.1-1-0.3L20,11.6c-0.6-0.4-1-1-1-1.7V9H8.5
C7.7,9,7,8.3,7,7.5S7.7,6,8.5,6H9V5c0-0.6,0.4-1,1-1V0.5C10,0.2,10.2,0,10.5,0C10.8,0,11,0.2,11,0.5V4c0.6,0,1,0.4,1,1v1h7l0,0
c0.1-0.6,0.4-1.2,1-1.6l3.6-2.1c0.3-0.2,0.7-0.3,1-0.3h6.9c0.4,0,0.7,0.1,1,0.3L36,4.4C36.6,4.8,37,5.3,37,6l7,0V5
c0-0.6,0.4-1,1-1V0.5z"/>
</g>
</g>
</svg>

The issue is with transform-box. This is an experimental CSS property which is not supported by Microsoft Edge.
I didn't find workaround for transform-box on Microsoft Edge, so I can only give you a suggestion to replace the svg with gif picture on Microsoft Edge like this:
.drone .body {
fill: #000000;
}
.drone .wing {
fill: #000000;
animation: wing 5s linear forwards infinite;
transform-box: fill-box;
transform-origin: center;
}
#keyframes wing {
100% {
transform: rotateY(7200deg);
}
}
#supports (-ms-ime-align: auto) {
/* Edge 12+ CSS styles go here */
#pic {
display: block;
}
#drone1 {
display: none;
}
}
#media screen and (-webkit-min-device-pixel-ratio:0) and (min-resolution:.001dpcm) {
/* Chrome 29+ CSS styles go here */
#pic {
display: none;
}
#drone1 {
display: block;
}
}
<img id="pic" src="https://i.stack.imgur.com/9yOqm.gif" />
<svg id="drone1" class="drone" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1923 643" preserveAspectRatio="xMinYMin meet">
<g id="drone1-droneContainer">
<g class="wing left">
<path d="M13,2c-0.6,0-1-0.4-1-1s0.4-1,1-1s8,0.4,8,1S13.6,2,13,2z" />
<path d="M8,2C7.4,2,0,1.6,0,1s7.4-1,8-1s1,0.4,1,1S8.6,2,8,2z" />
</g>
<g class="wing right">
<path d="M48,2c-0.6,0-1-0.4-1-1s0.4-1,1-1s8,0.4,8,1S48.6,2,48,2z" />
<path d="M43,2c-0.6,0-8-0.4-8-1s7.4-1,8-1s1,0.4,1,1S43.6,2,43,2z" />
</g>
<g class="body">
<path d="M45,0.5C45,0.2,45.2,0,45.5,0S46,0.2,46,0.5V4c0.6,0,1,0.4,1,1v1h0.5C48.3,6,49,6.7,49,7.5S48.3,9,47.5,9H37v0.9
c0,0.7-0.4,1.4-1,1.7l-3.6,2.1c-0.3,0.2-0.7,0.3-1,0.3h-6.9c-0.4,0-0.7-0.1-1-0.3L20,11.6c-0.6-0.4-1-1-1-1.7V9H8.5
C7.7,9,7,8.3,7,7.5S7.7,6,8.5,6H9V5c0-0.6,0.4-1,1-1V0.5C10,0.2,10.2,0,10.5,0C10.8,0,11,0.2,11,0.5V4c0.6,0,1,0.4,1,1v1h7l0,0
c0.1-0.6,0.4-1.2,1-1.6l3.6-2.1c0.3-0.2,0.7-0.3,1-0.3h6.9c0.4,0,0.7,0.1,1,0.3L36,4.4C36.6,4.8,37,5.3,37,6l7,0V5
c0-0.6,0.4-1,1-1V0.5z" />
</g>
</g>
</svg>

What version is your edge browser? Transform-Origin should be supported
Another way for you to fix this, might be the use of cssSandpaper

Related

CSS Animated Radial Graph overflow after animation SVG

I've encountered a problem when using the css disarray function. The "front" circle clips over after animation has finished and doesnt "Start" at origin point of the animation. After the animation has completed, the filled stroke clips back past the origin point. Can someone Please help me out - I've tried reading up on SVG elements and have fiddled with the code for a few hours now and I still cant get it to animate properly.
Thank you so much for your support. Here is the code I am working with.
.radial-graph-container {
display: flex;
justify-content: center;
flex-direction: column;
padding-bottom: 2.4rem;
}
.radial-graph-container .chart-container .back {
stroke: #101114;
stroke-width: 10;
}
.radial-graph-container .chart-container .front {
stroke: #94d82d;
stroke-width: 15;
stroke-dasharray: 210;
/* Works fine with values above 300 */
transform: rotate(-90deg);
transform-origin: center;
}
.front {
animation: fill 1s reverse;
}
<div class="radial-graph-container">
<svg width="200" height="200" class="chart-container">
<circle cx="100" cy="100" r="90" class="back" fill="none" />
<circle cx="100" cy="100" r="90" class="front" fill="none" />
<g class="graph-center-txt">
<text
x="100"
y="100"
alignment-baseline="central"
text-anchor="middle"
id="percentage-social-media-usage"
>
42%
</text>
</g>
</svg>
<p class="graph-info-txt">
Description Text Here
</p>
</div>
Your animation part was missing: (the #keyframes section)
.radial-graph-container {
display: flex;
justify-content: center;
flex-direction: column;
padding-bottom: 2.4rem;
}
.radial-graph-container .chart-container .back {
stroke: #101114;
stroke-width: 10;
}
.radial-graph-container .chart-container .front {
stroke: #94d82d;
stroke-width: 15;
stroke-dasharray: 210;
/* Works fine with values above 300 */
transform: rotate(-90deg);
transform-origin: center;
}
.front {
animation: fill 1s reverse;
}
#keyframes fill {
0% {
r: 90;
}
100% {
r: 0;
}
}
<div class="radial-graph-container">
<svg width="200" height="200" class="chart-container">
<circle cx="100" cy="100" r="90" class="back" fill="none" />
<circle cx="100" cy="100" r="90" class="front" fill="none" />
<g class="graph-center-txt">
<text
x="100"
y="100"
alignment-baseline="central"
text-anchor="middle"
id="percentage-social-media-usage"
>
42%
</text>
</g>
</svg>
<p class="graph-info-txt">
Description Text Here
</p>
</div>

How to prevent an outline on SVG path when animating clip path?

I'm trying to get this animation to work in my website. For some reason the layered paths show through so a thin white outline for the path (that's animated in) is visible ruining the animation, despite the fact the paths are identical in size. I wondered if anyone has any suggestions on how to prevent this?
I've made a jsFiddle and added the code below. If you change the background for the body to black it's even clearer.
Any help would be appreciate.
body {
background: #333;
padding: 2em;
}
svg {
display: block;
left: 50%;
max-width: 8em;
position: absolute;
top: 50%;
transform: translate(-50%,-50%);
}
#rect {
animation: slideOver 5s linear infinite;
}
#keyframes slideOver {
0% {
transform: translateX(0);
}
100% {
transform: translateX(100%);
}
}v
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 250 346">
<defs>
<clipPath id="clip-path">
<rect id="rect" x="0" y="0" height="346" width="250"/>
</clipPath>
</defs>
<path fill="#fff" d="M1.9 0h245.9v58H1.9zM250.1 139.9l-43.8-43.8-81.2 81.2-81.3-81.2L0 139.9l81.2 81.2L0 302.3l43.8 43.9 81.3-81.2 81.2 81.2 43.8-43.9-81.2-81.2"/>
<path clip-path="url(#clip-path)" fill="#000" d="M1.9 0h245.9v58H1.9zM250.1 139.9l-43.8-43.8-81.2 81.2-81.3-81.2L0 139.9l81.2 81.2L0 302.3l43.8 43.9 81.3-81.2 81.2 81.2 43.8-43.9-81.2-81.2"/>
</svg>

CSS animation slowed down/do not complete after adding more sections to page

I am having trouble with CSS animations I added to a Webflow site in an Embed element. Before I added more sections to the page, the animations played a lot faster and the animation fully completed. Now after working on the site and adding more sections, the animations are slow and some do not complete.
Here is the embedded code I am using, if anyone could tell me why this is happening I would greatly appreciate the help :)
I am guessing the code is targeting the body? And that is why the animations got messed up when adding more sections?
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" style="height:64px;width:64px">
<path fill="none" stroke="currentColor" stroke-width="2" stroke-miterlimit="10" d="M18 1h28v61L32 48 18 62z" stroke-dasharray="190,192"/>
<path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="bevel" stroke-miterlimit="10" d="M23 22l7 7 13-13" stroke-dasharray="29,31"/>
</svg>
<style>
selector {
property: value;
}
svg {
height: 100%;
width: 100%;
}
path {
stroke-dasharray: 300
;
animation: draw 2s normal;
}
#keyframes draw {
from {
stroke-dashoffset: 300
}
to {
stroke-dashoffset: 100%;
}
}
</style>
https://rova-roofing.webflow.io
icon animation section
What you are looking for is animation speed. Try this:
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" style="height:64px;width:64px">
<path fill="none" stroke="currentColor" stroke-width="2" stroke-miterlimit="10" d="M18 1h28v61L32 48 18 62z" stroke-dasharray="190,192"/>
<path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="bevel" stroke-miterlimit="10" d="M23 22l7 7 13-13" stroke-dasharray="29,31"/>
</svg>
<style>
svg {
height: 100%;
width: 100%;
}
path {
stroke-dasharray: 300px;
;
animation: draw 5s normal; /*Change the speed right here*/
}
#keyframes draw {
from {
stroke-dashoffset: 300px;
}
to {
stroke-dashoffset: 100%;
}
}
</style>

CSS animation do not work for svg in <img>

I am trying to animate an SVG in image/object tag but it is not working
svg {
width: 100%;
height: 200px;
}
.rotate-45 {
transform-origin: center;
transform: rotate(45deg);
}
.rotate {
transform-origin: center;
animation: rotate 1s ease-in-out infinite;
}
.rotate-back {
transform-origin: center;
animation: rotate 1s ease-in-out infinite;
animation-direction: alternate;
}
.left {
animation: move 1s ease-in-out infinite;
}
.right {
animation: move 1s ease-in-out infinite;
}
#keyframes rotate {
100% {
transform: rotate(calc(90deg + 45deg));
}
}
#keyframes move {
50% {
transform: translate(-30px, -30px);
}
}
<svg width="100%" height="100%" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<g transform="translate(500,500)">
<rect class="rotate-45 rotate-back" x="-5" y="-5" width="10" height="10" stroke="#00a99d" stroke-width="20" fill="none" />
<rect class="rotate-45 rotate" x="-50" y="-50" width="100" height="100" stroke="#00a99d" stroke-width="20" stroke-linejoin="bevel" fill="none" />
<g transform="translate(-50,0) rotate(-45)">
<polyline class="left" points="40,-40 50,-50 -40,-50 -50,-40 -50,50 -40,40" stroke="#00a99d" stroke-width="20" fill="none" />
</g>
<g transform="translate(50,0) rotate(135)">
<polyline class="right" points="40,-40 50,-50 -40,-50 -50,-40 -50,50 -40,40" stroke="#00a99d" stroke-width="20" fill="none" />
</g>
<text y="-140" text-anchor="middle" font-weight="bold" font-size="3em" font-family="sans-serif">loading data...</text>
</g>
</svg>
How to animate the SVG inside the image tag along side with CSS
Here is a plunker for that code https://plnkr.co/edit/TdfR7cpVaQArtcUs0Hro?p=preview
You can't animate the internals of an <img> from the outside. Even if it is an SVG. There are two reasons for this:
CSS doesn't apply across document boundaries, and
Images referenced via an <img> must be self contained.
Animations should work if you put the CSS inside the external SVG (in a <style> element as normal).
Note also that you will need to change the way you do transform-origin. The way it works in Chrome is convenient, but it is wrong according to the current spec. It won't work on other browsers like Firefox.
<svg width="100%" height="100%" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<style>
.rotate-45 {
transform-origin: 0px 0px;
transform: rotate(45deg);
}
.rotate {
transform-origin: 0px 0px;
animation: rotate 1s ease-in-out infinite;
}
.rotate-back {
transform-origin: 0px 0px;
animation: rotate 1s ease-in-out infinite;
animation-direction: alternate;
}
.left {
animation: move 1s ease-in-out infinite;
}
.right {
animation: move 1s ease-in-out infinite;
}
#keyframes rotate {
100% {
transform: rotate(135deg);
}
}
#keyframes move {
50% {
transform: translate(-30px, -30px);
}
}
</style>
<g transform="translate(500,500)">
<rect class="rotate-45 rotate-back" x="-5" y="-5" width="10" height="10" stroke="#00a99d" stroke-width="20" fill="none"/>
<rect class="rotate-45 rotate" x="-50" y="-50" width="100" height="100" stroke="#00a99d" stroke-width="20" stroke-linejoin="bevel" fill="none"/>
<g transform="translate(-50,0) rotate(-45)"><polyline class="left" points="40,-40 50,-50 -40,-50 -50,-40 -50,50 -40,40" stroke="#00a99d" stroke-width="20" fill="none"/></g>
<g transform="translate(50,0) rotate(135)"><polyline class="right" points="40,-40 50,-50 -40,-50 -50,-40 -50,50 -40,40" stroke="#00a99d" stroke-width="20" fill="none"/></g>
<text y="-140" text-anchor="middle" font-weight="bold" font-size="3em" font-family="sans-serif">loading data...</text>
</g>
</svg>
You can use <?xml-stylesheet href="style.css" type="text/css"?> if you dont want to have to embed it for img tags to work. The above code will work in an object tag
If you want img tags to work do what Kaiido suggested and embed it.
If you're working with pure JavaScript or some other environment that doesn't automatically include SVG's inline in your HTML output (eg like create-react-app does), here's a solution that might come in handy for you:
<img id="logo" src="logo.svg" />
<script>
// load logo inline for animation on hover
const loadLogo = async () => {
// get logo, parse source text, and insert text into doc
document.write(await (await fetch("logo.svg")).text());
// remove fallback img logo
document.querySelector("img#logo").remove();
};
loadLogo();
</script>
All this does is attempt to load an image at a given url/path, then insert its text contents right into the document, in place. Then you can style it from other style sheets, manipulate sub-elements with javascript, have user interaction animations, and etc. If it fails to load for any reason, there is an <img> there as a backup.
This could be written to be more general too, but this was just a quick solution I used once.
Another solution is to just embed the SVG using <object> as explained here, though that could have some limitations depending on what you want to do.

How to show SVG donut chart in IE?

I have created a very nicely animated chart that looks like this.
<div>Some percentage</div>
<div class="bigbox">
<div class="centered">
<div class="item t1">
<div class="graphicsContent">51%</div>
<svg width="144px" height="144px" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>
<circle id="circle1" class="circle_animation" r="56" cy="72" cx="72" stroke-width="16" stroke="blue" fill="none"/>
</g>
<g>
<circle id="innerCircle1" r="44" cy="72" cx="72" stroke-width="2" stroke="#b1b1b1" fill="none"/>
</g>
</svg>
</div>
</div>
</div>
As you can see, I used SVG. It seems to work fine anywhere else but in IE. I read that IE has a lot of issues regarding CSS3 animations. SMIL doesn't seem to solve my problems. And I don't even care if the graphic is completely animated in IE as long as it just shows the whole content.
Should I stay away from SVG if I want to create a cross-browser solution or is there something I should add to achieve the desired (or even partially desired) result in IE? I would appreciate any suggestion.
Dash-arrayoffset animated
**Does not work in IE**, even if the [documentation][1] does say its css animatable
So **[Harry][2]** converted it to use dash-array instead.
I reveresed the prosess with: animation: t1 1s ease-out reverse forwards;
Why would you do that?
Because when an animation fails in IE it goes back to its initial value.
The old initial value was: stroke-dasharray: 351.68;
this is 0% of the circle
The new initial value is: stroke-dasharray: 170.7, 351.68;
and this is about 51% of the circle.
.bigbox {
width: 50%;
}
.item {
position: relative;
}
.graphicsContent {
text-align: center;
position: absolute;
line-height: 144px;
width: 100%;
font-size: 1.250em;
}
svg {
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
}
.circle_animation {
stroke-dasharray: 170.7, 351.68;
}
.t1 .circle_animation {
-webkit-animation: t1 1s ease-out reverse forwards;
animation: t1 1s ease-out reverse forwards;
}
#-webkit-keyframes t1 {
0% {
stroke-dasharray: 170.7, 351.68;
}
100% {
stroke-dasharray: 0, 351.68;
}
}
#keyframes t1 {
0% {
stroke-dasharray: 170.7, 351.68;
}
100% {
stroke-dasharray: 0, 351.68;
}
}
<div>Some percentage</div>
<div class="bigbox">
<div class="centered">
<div class="item t1">
<div class="graphicsContent">51%</div>
<svg width="144px" height="144px" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>
<circle id="circle1" class="circle_animation" r="56" cy="72" cx="72" stroke-width="16" stroke="blue" fill="none" />
</g>
<g>
<circle id="innerCircle1" r="44" cy="72" cx="72" stroke-width="2" stroke="#b1b1b1" fill="none" />
</g>
</svg>
</div>
</div>
</div>
As you say, 'SMIL doesnt seem to your your problems' - The reason behind this is because IE does not suspport SVG SMIL animation - as you can see here http://caniuse.com/#search=svg%20animation
Would you be happy with the whole chart (i.e. the circle and the blue bar with percentage) being displayed, or just the percentage without the circle?