I have a website where I fade in a set of SVG icons which have the filter: drop-shadow rule applied. This works fine on desktop, however on iOS the shadow gets cut off once the animation finishes.
For example, this is the html:
<div class="fade-in">
<svg class="shadow" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="50" fill="white"/>
</svg>
</div>
The css:
#keyframes fade-in {
from {
opacity: 0.0;
}
to {
opacity: 1.0;
}
}
.fade-in {
animation: fade-in 2s;
}
.shadow {
filter: drop-shadow(0 0.1rem 0.7rem black);
}
JS Bin:
https://jsbin.com/yonifusomo/edit?html,css,output
Result on iOS after the animation finishes:
Safari has multiple bugs related to shadows and various animations. Luckily, looks like this one is not the worst. Adding a -webkit-transform: translateZ(0); property to your .fade-in class did the trick for me.
For more info: this post is pretty similar to yours, and it contains almost same advice.
Related
I'm trying to apply a svg "Turbulence" filter on an image on my website.
The thing is that it looks well on FireFox and Chrome :
But looks horrible on safari :
It seems that Safari is "spliting" my image into tiles... Do you have any idea ?
here's my code :
<svg>
<filter id="turbulence" x="0" y="0" width="100%" height="100%">
<feTurbulence
id="sea-filter"
numOctaves="3"
seed="2"
baseFrequency="0.02 0.05"
></feTurbulence>
<feDisplacementMap
scale="20"
in="SourceGraphic"
></feDisplacementMap>
<animate
xlinkHref="#sea-filter"
attributeName="baseFrequency"
dur="120s"
keyTimes="0;0.5;1"
values="0.02 0.06;0.04 0.08;0.02 0.06"
repeatCount="indefinite"
/>
</filter>
</svg>
<div className={styles.sea} style={{ background: `url(${sea})` }}></div>
CSS :
.sea {
position: absolute;
inset: 0;
width: 100vw;
height: 100%;
background-image: url("../../assets/images/Hero/Sea/sea.webp");
background-size: cover;
filter: url("#turbulence");
animation: floating 80s ease forwards infinite;
transform: translateY(0) scale(1.25);
}
I tried to remove my animation and my transform but it doesn't work...
Thanks by advance !
This is a bug in Safari: when a turbulence is transformed, it loses its tile-stitching. Take off the transform: scale(1.2) and it works fine in desktop Safari at least.
Hygiene tip - always add color-interpolation-filters="sRGB" to an SVG filter so you don't trigger one of Safari's many bugs in the default linearRGB color-space.
I am trying to animate some elements of an image in svg. To test the animation I first tried it on the whole image to check that it works well (it does). But when I change the class state-indicator-illustration by the id note-double-1 (id of the element to animate) the element note-double 1 disappears completely without me understanding why.I specify that to test I inserted the image "line by line" in the HTML code.
Here is the code (i put jsfiddle to avoid very long message) :
JsFiddle: https://jsfiddle.net/pju2ateL/2/
Thanks for your help,
elshiri.
As I've commented: you need to remove the transform attribute of the path.
In order to preserve your transformations I am wrapping the path in a group and transform the group instead of transforming the path. Also I had to change the viewBox since otherwise the path falls outside the svg canvas.
As you can see the css animation is working.
/* .state-indicator-illustration is working */
#note-double-1 {
/*overflow: hidden;*/
transform: translateY(0px);
animation: float 6s ease-in-out infinite;
}
#keyframes float {
0% {
transform: translateY(0px);
}
50% {
transform: translateY(-20px);
}
100% {
transform: translateY(0px);
}
}
<svg xmlns="http://www.w3.org/2000/svg" width="244" height="149.388" viewBox="-15 -320 244 149.388">
<g id="off" transform="translate(-1090, -390)">
<g transform="translate(-28.904 -320.214)" >
<path id="note-double-1" d="M1114.926,434.328l5.138-22.688,22.647,1.41c-.05.226-.093.412-.133.6q-2.918,12.882-5.824,25.761a5.089,5.089,0,0,1-3.018,3.727,7.907,7.907,0,0,1-9.016-2.153c-2.277-2.776-1.476-6.41,1.8-7.774a7.7,7.7,0,0,1,8.184,1.341c.1.083.205.172.31.245h.067l3.237-14.3c-1.28-.081-2.527-.164-3.772-.245-4.355-.272-8.713-.535-13.066-.821-.412-.029-.524.113-.61.49-1.4,6.229-2.861,12.445-4.2,18.686a5.393,5.393,0,0,1-4.558,4.48,7.783,7.783,0,0,1-8.129-3.455,4.664,4.664,0,0,1,1.414-6.408,7.077,7.077,0,0,1,6.186-.777,8.54,8.54,0,0,1,1.767.758A17.8,17.8,0,0,1,1114.926,434.328Z"/>
</g>
</g>
</svg>
I have SVG which contain two rings: inner and outer. I'm trying to create an animation, where svg on hovered shows inner ring instantly, and outer after 300ms.
I've tried with keyframes animation, but apparently I cannot trigger child element animation when parent is hovered. See this pen.
The problem was that you were triggering the keyframe animation on the <svg> element itself, then telling one of the elements inside it to have a delayed animation.
You can only add properties like animation-delay on the elements being animated, so I moved the animation to the <circle> elements. Here you go:
svg {
width: 202px;
height: 202px;
}
svg:hover circle {
animation: show-inner 1s;
}
svg circle.ring-outer {
animation-delay: 300ms;
}
#keyframes show-inner {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<svg viewbox="0 0 202 202" preserveAspectRatio="xMidYMid meet" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle cx="101" cy="101" r="100" stroke="#7b82c7" stroke-width="1" fill="none" class="ring-outer"/>
<circle cx="101" cy="101" r="76" stroke="#7b82c7" stroke-width="1" fill="none" class="ring-inner"/>
</svg>
CSS allows to change the color of SVG like this
.clr {fill: green;}
But when I apply animation with the same fill attributes nothing seems to work. What should I do?
<svg width="800" height="600" style="background-color:lightblue">
<circle class="clr" cx="610" cy="240" r="4" fill="gold" />
<style>
.clr {animation: col 3s linear infinite;}
#keyframes col {
0%,71% {fill:none}
72% {fill:black}
75%,100% {fill:none}
}
</style>
</svg>
Its working as expected, I just increased the circle radius and changed its position to show it on 50x and 50y,
.color {animation: col 3s linear infinite;}
#keyframes col {
0%,71% {fill:none}
72% {fill:black}
75%,100% {fill:none}
}
<svg width="800" height="600" style="background-color:lightblue">
<circle class="color" cx="50" cy="50" r="30" fill="gold" />
</svg>
You Just add fill:black in #keyframes section. change it to green like this:
.color {animation: col 3s linear infinite;}
#keyframes col {
0%,71% {fill:none}
72% {fill:green}
75%,100% {fill:none}
}
<svg width="800" height="600" style="background-color:lightblue">
<circle class="color" cx="610" cy="240" r="4" fill="gold" />
</svg>
and don't want to use .color {fill: green;}.
You cannot animate from none (nothing) to green (something) for a smooth transition. Instead do:
#keyframes col {
0%, 71% { fill: none; } /* change attribute value to `inherit` */
72% { fill: black; }
75%, 100% { fill: none; } /* or change value to `currentcolor` */
}
Resulting in the following:
#keyframes col {
0%, 71% { fill: inherit; }
72% { fill: black; }
75%, 100% { fill: currentcolor; }
}
Then play around with the animation attribute or element.animate to achieve desired effect.
Following is the example from #Muhammad (because it is easier to see than the OP's example of a small dot in the lower right) of an svg with an inline style section. As I read the specification, it should work as is. However, browser support still seems to be lacking 3 years later, now in 2020.
SVG 2 Requirement: Add HTML5 ‘style’ element attributes to SVG's ‘style’ element.
Resolution: SVG 2 ‘style’ element shall be aligned with the HTML5 ‘style’ element.
Purpose: To not surprise authors with different behavior for the ‘style’ element in HTML and SVG content.
I have used VS Code with a plugin called jock.svg and the animation works as expected in the live preview pane. Just copy and save the svg code "as is" with a file extension of "svg".
It is hard to know what animation the OP was going for without a description because the code snippet is said to be not working.
For clarity I will describe what this example does: It displays a briefly (3% of the time) flashing black circle on a light blue background in the top left corner. Note that the original "gold" fill is ignored when the animation is working. Today in Safari (Mac, iPad), Chrome (iPad) and Edge (iPad), all I see is the "gold" circle. No animation is applied. Please comment if (when) your browser works. I suspect this hole in browser support will be filled in the future.
[Edit]
It works in Chrome 81.0.4044.92 (Mac)
<svg width="800" height="600" style="background-color:lightblue">
<circle class="color" cx="50" cy="50" r="30" fill="gold" />
<style>
.color {animation: col 3s linear infinite;}
#keyframes col {
0%,71% {fill:none}
72% {fill:black}
75%,100% {fill:none}
}
</style>
</svg>
I have found this question that's been answered and seems to achieve a radial wipe animation with an SVG.
I am looking to achieve a border: 1px solid green; effect like the following example:
What I would like to know though is if this is possible with pure CSS —that would be ideal.
If it's not achievable with CSS, how would I tackle this type of thing with SVG?
CSS is not the right tool for animations like these. While you can do it with CSS, best is to make use of SVG. For a pure CSS version you could try adapting the snippet provided in my answer here but I wouldn't really be recommending it because as you can see it is very complex.
All you have to do is use a circle element, set its stroke-dasharray equal to the circumference of the circle and then animate the stroke-dashoffset like in the below snippet.
The stroke-dasharray property creates a dotted line stroke for the cirlce (the border) where each of the stroke and the dash between them will have the length as specified for the property.
The stroke-dashoffset property specifies the offset at which the circle's stroke should start. When the offset is at 0, the green colored stroke is visible whereas when the offset is at 314 (equal to the circumference), the dash in between strokes become visible. Thus it ends up producing a wipe effect.
svg {
height: 100px;
width: 100px;
transform: rotate(-90deg);
}
circle {
stroke: green;
fill: none;
stroke-dasharray: 314; /* equal to circumference of circle 2 * 3.14 * 50 */
animation: wipe 2s linear infinite;
}
#keyframes wipe {
0% {
stroke-dashoffset: 0;
}
30%, 50% {
stroke-dashoffset: 314;
}
80%, 100% {
stroke-dashoffset: 0;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<svg viewBox='0 0 100 100'>
<circle cx='50' cy='50' r='40' />
</svg>
The above sample uses an infinite animation and so the wipe and repaint would run continuously. If it has to be toggled on/off then it would be better to use transition like in the below snippet. I have done this on :hover but you can easily adapt it to click or other events.
svg {
height: 100px;
width: 100px;
transform: rotate(-90deg);
}
circle {
stroke: green;
fill: none;
stroke-dasharray: 314; /* equal to circumference of circle 2 * 3.14 * 50 */
stroke-dashoffset: 0; /* initial setting */
transition: all 2s;
}
svg:hover circle{
stroke-dashoffset: 314;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<svg viewBox='0 0 100 100'>
<circle cx='50' cy='50' r='40' />
</svg>