Fill svg from left to right - html

I'm new to svg, I was trying to fill color in a path/circle. I was able to fill it with transition.
But I was wondering is there a way to fill the svg from left to right of the path/circle.
SVG
<svg viewBox="0 0 160 160" width="160" height="160">
<circle cx="80" cy="80" r="50" />
</svg>
CSS
circle {
transition: all 3s;
}
JS
setTimeout(function(){
$('circle').css('fill', 'red');
},300);
How to fill in particular direction, like left to right?
Codepen

As "fill left to right" can mean a lot of things, I made a few examples:
Moving a gradient:
I would suggest using the SVG <linearGradient> and <animate> tags. That way you don't need the JS or CSS.
Here is a guide to animating gradients in SVG: http://designmodo.com/animate-svg-gradients/
And one to SVG animations in general: https://css-tricks.com/guide-svg-animations-smil/
In your case (fill left to right), I would do it like this:
<svg viewBox="0 0 160 160" width="160" height="160">
<defs>
<linearGradient id="lightGradient">
<stop offset="0%" stop-color="red">
<animate attributeName="stop-color" values="black; red" dur="3s" fill="freeze" />
</stop>
<stop offset="100%" stop-color="black">
<animate attributeName="stop-color" values="black; red" dur="3s" fill="freeze" begin="3s"/>
</stop>
</linearGradient>
</defs>
<circle cx="80" cy="80" r="50" fill="url(#lightGradient)"/>
</svg>
Technically it's cheating, as the gradient doesn't actually move, but the colours on both sides change, but it looks pretty much the same. It starts out with a gradient from black to black, then the left side changes to red, giving the illusion that red moves in from the left. After the left side is red, the right side changes from black to red and it looks like the gradient is moving to fill the whole circle.
Clear border between left and right:
Probably best to use a <clip-path> for this:
<clipPath id="left-to-right">
<rect x="130" y="30" width="0" height="100" >
<animate attributeName="width" values="0;100" dur="3s" fill="freeze"/>
</rect>
</clipPath>
...
<circle cx="180" cy="80" r="50" fill="black"/>
<circle cx="180" cy="80" r="50" fill="red" clip-path="url(#left-to-right)"/>
This one draws a black circle, then draws a red circle over it inside a growing clipping area.
One circle obscuring the other:
Again, <clip-path> works for this:
<clipPath id="steady">
<circle cx="280" cy="80" r="50"/>
</clipPath>
...
<circle cx="280" cy="80" r="50" fill="red" clip-path="url(#steady)">
<animate attributeName="cx" values="180;280" dur="3s" fill="freeze"/>
</circle>
This one uses a circular clipping area and moves the second circle within it.
Here it is in Codepen: http://codepen.io/anon/pen/aOKeYQ

It's possible, but not with just using 'fill'.
You can e.g do a linear gradient fill, with two stops, one being the color you want and the other fully transparent. Then animate the offset of the second gradient stop. For an example see here.
Another way is using a clip-path, where the clip shape is a rect that is animated e.g from left to right. That can then be applied to a copy of the shape that you want to fill like this. Basically you need the starting shape (unfilled) and an ending shape (filled), where the final shape gets displayed by animating the clip-path.

Related

how to animate this svg image like water flow in Html css?

i want to use this animated as background. Svg fill animation is need to animate this svg image,
but, i can't understood that.
image link i want
<svg class="translate-y-[25%] translate-x-1/3 transform-gpu lg:w-[725px] 2xl:h-[940px] 2xl:w-[979px]" viewBox="0 0 979 940" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M916.44 542.73C916.44 759.742 1221.12 893.447 485.73 935.665C-249.656 977.884 73.651 701.676 55.0199 542.73C36.3888 383.785 210.098 445.489 210.098 316.311C210.098 187.134 286.044 270.936 393.995 193.072C501.947 115.207 360.243 108.245 679.166 13.9659C998.088 -80.3132 916.44 325.718 916.44 542.73Z" fill="url(#paint0_radial_2978_41613)"></path>
<defs>
<radialGradient id="paint0_radial_2978_41613" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(754.239 148.024) rotate(129.699) scale(1296.28 1230.91)">
<stop stop-color="#42ADDB"></stop>
<stop offset="1" stop-color="#9AFAFA"></stop>
</radialGradient>
</defs>
</svg>

Background color and svg gradient at top of it bring svg at fornt

i need to get this effect in css.
it's gradient with red as svg this is it:
and black background in the css:
.body-element {
background-color: black;
text-align: left;
background-image: url("data:image/svg+xml;base64, ....");
}
Now the effect is only the back background. How to bring this svg to front of this background ?
I know i can make full img in figma but i have to use background in css.
I don't know what exact effect you want to achieve yet you'll have to use SVG opacity in the gradient to "show through" your background. Here's your SVG, play with the background color of the first rectangle in the code (mimicking your black background):
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400">
<defs>
<linearGradient id="linGradient1" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0" stop-color="#333333" stop-opacity="0.25" />
<stop offset="1" stop-color="darkred" stop-opacity="0.75" />
</linearGradient>
<mask id="gradient-mask1">
<rect x="100" y="100" width="200" height="200" fill="url(#linGradient1)" />
</mask>
</defs>
<rect x="0" y="0" width="400" height="400" fill="black" />
<rect x="100" y="100" width="200" height="200" fill="url(#linGradient1)" />
</svg>
Actually I have left the SVG mask definition as well in the code, search Mozilla SVG specification how to use it and maybe it will also spawn more creativity with SVG simple effects.

How can I make the SVG animation seamless and smooth?

I have animated the SVG, to give a handwriting effect, I want to make the animation more seamless, as the letter "W" appears in the animation, it makes the other part of the letter appear as well, and I can't decrease the stroke-width as the rest of the part of the letter will not appear completely, please guide me along on what can be done.
As I cant upload the code here its SVG and exceeding more than 35,000 characters, so please do check the CodePen.
HTML Code
<defs>
<clipPath id="clip-path" transform="translate(0 0)">
<path id="w" d="M47.205,44.721c-.1.062-.191.119-.262.169a1.172,1.172,0,0,0-.192.17,1.237,1.237,0,0,0-.155.208,1.71,1.71,0,0,0-.13.285L42.677,55.6q-.354-.956-.708-1.9-.307-.8-.655-1.694t-.623-1.6L38.8,55.6Q37.7,52.9,36.825,50.73q-.37-.925-.739-1.818c-.247-.6-.467-1.134-.662-1.618s-.357-.883-.485-1.2-.2-.508-.223-.57a1.835,1.835,0,0,0-.293-.47,1.326,1.326,0,0,0-.539-.332H36.7a.519.519,0,0,0-.355.4.832.832,0,0,0,.093.539l2.836,7.18,1.077-3.3q-.215-.57-.493-1.247t-.532-1.279c-.17-.4-.313-.747-.432-1.04s-.187-.464-.208-.516a1.529,1.529,0,0,0-.223-.409,1.143,1.143,0,0,0-.532-.332h2.711a.5.5,0,0,0-.315.4,1.016,1.016,0,0,0,.07.539l.817,2.033.8-2.2a.886.886,0,0,0,.068-.479q-.039-.2-.347-.293h1.633a2.841,2.841,0,0,0-.254.17,1.007,1.007,0,0,0-.169.161,1.148,1.148,0,0,0-.124.185,2.582,2.582,0,0,0-.116.254l-1.155,3.034,1.556,4.313L45.652,45.6a1.01,1.01,0,0,0,.062-.533.513.513,0,0,0-.355-.346h1.849Z" style="fill: none" />
</clipPath>
</defs>
<g id="w-grp">
<g style="clip-path: url(#clip-path)">
<polyline class="logo-path m-1" id="w-path" points="35.084 43.989 39.663 55.599 38.796 55.599 38.609 55.136 42.916 43.989 38.968 43.989 43.484 55.599 42.677 55.597 42.474 55.101 46.67 43.989" style="fill: none;stroke: #191717;stroke-miterlimit: 10;stroke-width: 3px" />
</g>
</g>
CodePen: https://codepen.io/ToxifiedM/pen/MWKeERr
Linked Question 1: A JQuery Function For SVG, To Execute 2nd Animation As Soon As, 1st Animation Completes?
Linked Question 2: To Control SVG CSS Based Animation Using Jquery?
Linked Question 3: To Control The Speed Of Multiple SVG Elements Using Jquery?
This is how I would do it:
I'm using a polyline element that I am clipping with a V like path. In order to make the W I'm using the clipped polyline twice. I am animating the stroke-dashoffset of the use elements, the second element with a 1s delay
svg{width:300px;border:solid}
use{
stroke-dasharray: 255;
stroke-dashoffset: 255;
animation: dash 1s linear forwards;
}
use:nth-of-type(2){
animation-delay:1s
}
#keyframes dash {
to {
stroke-dashoffset: 0;
}
}
<svg viewBox="30 80 250 150">
<defs>
<clipPath id="clip">
<path id="V" xmlns="http://www.w3.org/2000/svg" d="M52,90L103,210 110,210 160,90 152,90 110,190 66,90 52,90" stroke="black" fill="none" />
</clipPath>
<polyline id="poly" points="58,85 107,203 156,85" stroke="red" fill="none" stroke-width="19" clip-path="url(#clip)" />
</defs>
<use xlink:href="#poly" x="0" />
<use xlink:href="#poly" x="50" />
</svg>

A way to produce inner radial shadow hover image with svg

I'm looking for a way to produce an inner radial shadow hover any image with css and svg (or other ?).
Here is an example of what i would like to do (for header and footer parts)
Have you got any suggestions ? I would like a way the most cross browser as possible.
Thank you !
Do you mean like this?
body{background:black;}
svg{height:100vh; display:block; margin:0 auto;}
<svg viewBox="0 0 300 300">
<defs>
<radialGradient id="rg" cx=".5" cy=".5" r=".5">
<stop offset="30%" stop-color="white"></stop>
<stop offset="100%" stop-color="black"></stop>
</radialGradient>
<mask id="mascara">
<circle cx="150" cy="150" r="100" fill="url(#rg)"></circle>
</mask>
</defs>
<image xlink:href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/darwin300.jpg" height="240" width="250" style="mask: url(#mascara)"></image>
</svg>
You may need to detect the position of your mouse and use it as the center for the mask.

SVG pattern fill position from top right, instead of top left

Is it possible to assign the starting point of the svg pattern fill from top right instead of top left?
For instance, CSS has background-position but I'm having trouble finding an SVG alternative which allows the same functionality.
Here's a CSS example of what I'm trying to achieve with SVG pattern fill: https://jsfiddle.net/19bc20p6/
And this is how far I've gotten with the SVG: https://jsfiddle.net/56cp4xwh/
The equivalent of your blue panel pattern in SVG is as follows:
<svg width="50vw" height="100vh">
<defs>
<linearGradient id="blue" x1="100%" y1="100%" x2="0%" y2="0%">
<stop offset="50%" stop-color="skyblue"/>
<stop offset="50%" stop-color="navy"/>
</linearGradient>
<pattern id="panel-one" patternUnits="userSpaceOnUse" width="20" height="20" x="100%" y="0%">
<rect width="20" height="20" fill="url(#blue)"/>
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#panel-one)"/>
</svg>
The x and y attributes of the <pattern> element effectively set the origin of the pattern. To set it to the top right, you would set it to x="100%" y="0%" as I have done here.
s it possible to assign the starting point of the svg pattern fill from top right instead of top left?
for this use transform: rotate(0deg);
i think its work