My goal is to create scrolling lines similar to this site. I have started using a simple SVG shape to try and get it to work. I can do a simple animation, but not sure how to fill a specific color from start to finish.
My SVG:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="75px" height="100px" viewBox="0 -450 1230 1640" preserveAspectRatio="xMidYMid meet">
<path class="path" d="M131.2,-318.8a672.4,672.4,0,0,1,0,1344.8" stroke="black" id="e7_circleArc" style="fill: none; stroke-width: 3px; vector-effect: non-scaling-stroke; stroke-dasharray: 5px, 5px;" />
My CSS
.path {
stroke-dasharray: 500;
stroke-dashoffset: 5000;
animation: dash 2s linear forwards;
}
#keyframes dash {
to {
stroke-dashoffset: 0;
}
}
You can see the working fiddle here - https://jsfiddle.net/cbd9L2L3/
I used the same method as the link you posted - animating the 'bottom' value of clip: rect() with jquery. With the difference that I went and used SVG shapes (one for the background and one for the one to be animated) Just a note that clip is apparently deprecated and has been replaced with clip-path. I tried with clip-path but couldn't achieve the same result.
Absolutely position both lines on top of one another if it's not obvious:
$('#line1-overlay').animate({
fontSize: 515 //some unimportant CSS to animate so we get some values - and height of the line
}, {
duration: 2000,
step: function (now, fx) { //now is the animated value from initial css value
$(this).css('clip', 'rect(0px, 217px, ' + now + 'px, 0px)')
}
});
.line-container {
position: relative;
}
.line {
position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="line-container">
<svg version="1.1" class="line" id="line1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="217px" height="515px" viewBox="0 0 217 515" enable-background="new 0 0 217 515" xml:space="preserve">
<path fill="#FFFFFF" stroke="#CCCCCC" stroke-width="4" stroke-miterlimit="10" d="M77.229,10.222c64,22,142,140,129,203
c-13,63-152,60-186,118c-34,58,61,159,130,177"/>
</svg>
<svg version="1.1" class="line" id="line1-overlay" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="217px" height="515px" viewBox="0 0 217 515" enable-background="new 0 0 217 515" xml:space="preserve">
<path fill="#FFFFFF" stroke="#000000" stroke-width="4" stroke-miterlimit="10" d="M77.229,10.222c64,22,142,140,129,203
c-13,63-152,60-186,118c-34,58,61,159,130,177"/>
</svg>
</div>
Also: JSFiddle DEMO
Thanks partly to this answer.
Related
I'm trying to animate a dotted SVG circle like a progressbar - to fill itself in 3 seconds, but have a hard time achieving this effect with the dotted border. Here's the code I currently have and it animates, but not like a progress:
svg circle {
animation: dash 3s linear forwards;
}
#keyframes dash {
from {
stroke-dashoffset: 100;
}
to {
stroke-dashoffset: 0;
}
}
<svg class="progress-ring" viewBox="0 0 120 120" fill="none" width="120" height="120" xmlns="http://www.w3.org/2000/svg">
<circle stroke="#000000" pathLength="215" stroke-width="7" fill="transparent" stroke-dasharray="6 6" r="57" cx="60" cy="60"/>
</svg>
https://codepen.io/xtnciwuu-the-selector/pen/abLXOJO
Any help would be greatly appreciated
Here are two different examples. The first one is a bit "hacky" in that I hard coded the dasharray with all the dots, spaces and then a subsequent long space.
The second example makes use of a mask. The animated circle/dasharray is masked off, so it looks like smaller dashes.
It kind of gives you two different expressions of the same animation.
svg circle#c1 {
animation: dash1 3s linear forwards;
}
#keyframes dash1 {
from {
stroke-dashoffset: 36;
}
to {
stroke-dashoffset: 0;
}
}
svg circle#c2 {
animation: dash2 3s linear forwards;
}
#keyframes dash2 {
from {
stroke-dasharray: 0 36;
}
to {
stroke-dasharray: 36 36;
}
}
<svg class="progress-ring" viewBox="0 0 120 120" fill="none" width="120" height="120" xmlns="http://www.w3.org/2000/svg">
<circle id="c1" stroke="#000000" pathLength="36" stroke-width="7" fill="transparent"
stroke-dasharray="1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 36"
r="57" cx="60" cy="60" transform="rotate(-90 60 60)" />
</svg>
<svg class="progress-ring" viewBox="0 0 120 120" fill="none" width="120" height="120" xmlns="http://www.w3.org/2000/svg">
<defs>
<mask id="m1">
<circle stroke="white" pathLength="36" stroke-width="7" fill="transparent"
stroke-dasharray="1 1" r="57" cx="60" cy="60" />
</mask>
</defs>
<circle id="c2" mask="url(#m1)" stroke="#000000" pathLength="36" stroke-width="7"
fill="transparent" stroke-dasharray="18 36" r="57" cx="60" cy="60"
transform="rotate(-90 60 60)" />
</svg>
greeting
the next code(two circle) it was run when mouse pointer hover over it, so the circle color change from one to another. i edit it so it now look like fan or some rotation animation, but it still need mouse pointer to run.
i hope find help for edit it so it auto run, and keep repeat(loop).
<html>
<body>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="400px" height="400px" viewBox="0 0 100 100" xml:space="preserve">
<defs>
<style>
.another-circle {
stroke-dasharray: 10;
stroke-dashoffset: 500;
transition: stroke-dashoffset 1s linear ;
}
.another-circle:hover {
stroke-dashoffset: 0;
}
</style>
</defs>
<circle cx="50" cy="50" r="36" fill="transparent" stroke="red" stroke-width="4" />
<circle transform="rotate(-90 40 40)" class="another-circle" cx="30" cy="50" r="36" fill="transparent" stroke="blue" stroke-width="60" />
</svg>
</body>
</html>
thanks in advance
What about using animation instead? It will run without hovering or using JavaScript.
Instead of animating the dasharray (dashoffset) I will go for transform/rotate. The dasharray is a bit tricky in this case because it is cut off.
.another-circle {
stroke-dasharray: 10;
transform-origin: center;
animation: rotateme 1s linear infinite;
}
#keyframes rotateme {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
<svg xmlns="http://www.w3.org/2000/svg" width="400px" height="400px" viewBox="0 0 100 100" xml:space="preserve">
<circle cx="50" cy="50" r="36" fill="none" stroke="red" stroke-width="4" />
<circle class="another-circle" cx="50" cy="50" r="36" fill="none" stroke="blue" stroke-width="60" pathLength="200" />
</svg>
This question already has answers here:
Activate CSS3 animation when the content scrolls into view
(6 answers)
Closed 3 years ago.
.responsive {
width:200px;
float:left;
margin-top: 750px;
margin-bottom: 750px;
}
.st0 {
fill: #ffffff;
}
.st1 {
fill: none;
stroke: #afafaf;
stroke-width: 4;
stroke-miterlimit: 10;
}
.st2 {
fill: #ffffff;
stroke: #afafaf;
stroke-width: 4;
stroke-miterlimit: 10;
}
.st3 {
fill: none;
stroke: #2646ff;
stroke-width: 7;
stroke-linecap: round;
stroke-linejoin: round;
stroke-miterlimit: 10;
}
#responsive .st3 {
stroke-dasharray: 1932;
stroke-dashoffset: 0;
animation: responsive 4s ease-in-out 0s;
animation-direction: reverse;
}
#keyframes responsive {
to {
stroke-dashoffset: 1932;
}
}
<div class="responsive">
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px"
y="0px"
viewBox="0 0 1200 780"
style="enable-background:new 0 0 1200 780;"
xml:space="preserve"
>
<g id="Layer_1"></g>
<g id="Layer_6">
<g>
<g>
<path
class="st0"
d="M1198,772.2c0,2.8-2.2,5-5,5H7c-2.8,0-5-2.2-5-5V36.6c0-2.8,2.2-5,5-5h1186c2.8,0,5,2.2,5,5V772.2z"
/>
<path
class="st1"
d="M1198,772.2c0,2.8-2.2,5-5,5H7c-2.8,0-5-2.2-5-5V36.6c0-2.8,2.2-5,5-5h1186c2.8,0,5,2.2,5,5V772.2z"
/>
</g>
<line class="st1" x1="2" y1="688.2" x2="1198" y2="688.2" />
<ellipse class="st2" cx="559.9" cy="732.7" rx="16.9" ry="16.7" />
</g>
</g>
<g id="Layer_5">
<g>
<g>
<path
class="st0"
d="M1127.3,771.9c0,2.8-2.2,5-5,5H631.5c-2.8,0-5-2.2-5-5V194.2c0-2.8,2.2-5,5-5h490.8c2.8,0,5,2.2,5,5V771.9z"
/>
<path
class="st1"
d="M1127.3,771.9c0,2.8-2.2,5-5,5H631.5c-2.8,0-5-2.2-5-5V194.2c0-2.8,2.2-5,5-5h490.8c2.8,0,5,2.2,5,5V771.9z"
/>
</g>
<line class="st1" x1="626.5" y1="715.5" x2="1127.3" y2="715.5" />
</g>
</g>
<g id="Layer_4">
<g>
<g>
<path
class="st0"
d="M1198,771.9c0,2.8-2.2,5-5,5H976.8c-2.8,0-5-2.2-5-5V352.1c0-2.8,2.2-5,5-5H1193c2.8,0,5,2.2,5,5V771.9z"
/>
<path
class="st1"
d="M1198,771.9c0,2.8-2.2,5-5,5H976.8c-2.8,0-5-2.2-5-5V352.1c0-2.8,2.2-5,5-5H1193c2.8,0,5,2.2,5,5V771.9z"
/>
</g>
<line class="st1" x1="971.8" y1="732" x2="1198" y2="732" />
</g>
</g>
<g id="responsive">
<g>
<path
class="st3"
d="M2,35.9L2,772.2 C2,775 4.2,777.2 7,777.2 L1194.1,777.2"
/>
</g>
</g>
</svg>
</div>
Scroll down in the snippet to view the svg + animation.
I want to start this animation when svg (animation) is in view. How can I do this? I came across a lot of javascript code but the problem is it's all too complicated with different kind of classes etc. I just do wanna start the animation 1 time and then keep it in the ending state (so not looping or anything).
I gave the section .responsive some margin top and bottom, normally there is content in between the white areas.
If you wanna a simple solution, then WOW.js is your choice :)
Steps to add animation for your svg:
Install wow.js as it said in documentation of plugin.
Add wow classname to your animation wrapper, and start css animation on
.animated #responsive .st3 {
stroke-dasharray: 1932;
stroke-dashoffset: 0;
animation: responsive 4s ease-in-out 0s;
animation-direction: reverse;
}
This is example of how your wow.js init should look like :)
wow = new WOW(
{
boxClass: 'wow', // add this className to animation wrapper
animateClass: 'animated', // class added by lib, when your item are in view
offset: 0, // number of px before item appear on screen and animation starts
mobile: true, // default
live: true // `true` if you add items on page dynamically
}
)
wow.init();
I have a circular progress bar that has two paths. On one of those paths increases in length as the data comes in, eventually turning the entire circle red.
SVG HTML
<path d="M 50,50 m 0,-47 a 47,47 0 1 1 0,94 a 47,47 0 1 1 0,-94" stroke="#A9B0B7" stroke-width="4" fill-opacity="0">
</path>
<path id="path2" d="M 50,50 m 0,-47 a 47,47 0 1 1 0,94 a 47,47 0 1 1 0,-94" stroke="#EB483F" stroke-width="6" fill-opacity="0" style="stroke-dasharray: 295.416, 295.416; stroke-dashoffset: 250"></path>
</svg>
CSS (Just makes loading of red path smoother)
#path2 {
-webkit-transition-property: stroke-dashoffset; /* Safari */
transition-property: stroke-dashoffset;
-webkit-transition-duration: 1s; /* Safari */
transition-duration: 0.3s;
}
.viewbox {
width: 50%;
}
https://jsfiddle.net/z5yb5kr9/
I would like for the remaining gray portion to have an animation such as a small div running through it lighting it up. Something similar to this
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_loader
I believe that I need to add some sort of keyframe animation and put the div inside the Path of the svg but I am not sure exactly what the method for doing so is.
Here's one way you could do the pulsing anumation on a circular progress bar.
In order to get the pulse effect showing inside a growing progress bar, the most obvious way is to create the pulse effect as it's own animation, then mask it with the actually progress arc.
Firstly, let's start with the plain red progress bar. I've added a grow animation for testing.
.viewbox {
width: 50%;
}
#progress {
stroke-dasharray: 296 296;
stroke-dashoffset: 296;
animation: grow 5s ease-out infinite;
}
#keyframes grow {
100% { stroke-dashoffset: 0; }
}
<svg class="viewbox" viewBox="0 0 100 100">
<circle id="grey" cx="50" cy="50" r="47"
transform="rotate(-90 50 50)"
stroke="#A9B0B7" stroke-width="4" fill="none"/>
<circle id="progress" cx="50" cy="50" r="47"
transform="rotate(-90 50 50)" pointer-events="all"
stroke="#EB483F" stroke-width="6" fill="none"/>
</svg>
Next, let's create our pulse animation which mimics the example you gave in an answer that was deleted.
.viewbox {
width: 50%;
}
#pulse {
stroke-dasharray: 0 0 0 296;
animation: pulse 1.5s linear infinite;
}
#keyframes pulse {
33% { stroke-dasharray: 0 0 148 296; }
66% { stroke-dasharray: 0 50 200 296; }
100% { stroke-dasharray: 0 296 0 296; }
}
<svg class="viewbox" viewBox="0 0 100 100">
<rect width="100" height="100" fill="#EB483F"/>
<circle id="pulse" cx="50" cy="50" r="47"
transform="rotate(-90 50 50)" pointer-events="all"
stroke="white" stroke-width="8" stroke-opacity="0.4" fill="none"/>
</svg>
It's just a translucent circle (with a dash animation) on a red background.
The penultimate step is to convert the first example into the form we need for a mask. In masks, black is transparent and white is opaque.
.viewbox {
width: 50%;
}
#progress {
stroke-dasharray: 296 296;
stroke-dashoffset: 296;
animation: grow 5s ease-out infinite;
}
#keyframes grow {
100% { stroke-dashoffset: 0; }
}
<svg class="viewbox" viewBox="0 0 100 100">
<rect width="100" height="100" fill="black"/>
<circle id="progress" cx="50" cy="50" r="47"
transform="rotate(-90 50 50)" pointer-events="all"
stroke="white" stroke-width="6" fill="none"/>
</svg>
The final step is to combine the last two steps. We turn the previous step into a proper <mask> and use it to mask the pulse animation.
.viewbox {
width: 50%;
}
#progress {
stroke-dasharray: 296 296;
stroke-dashoffset: 296;
animation: grow 5s ease-out infinite;
}
#keyframes grow {
100% { stroke-dashoffset: 0; }
}
#pulse {
stroke-dasharray: 0 0 0 296;
animation: pulse 1.5s linear infinite;
}
#keyframes pulse {
33% { stroke-dasharray: 0 0 148 296; }
66% { stroke-dasharray: 0 50 200 296; }
100% { stroke-dasharray: 0 296 0 296; }
}
<svg class="viewbox" viewBox="0 0 100 100">
<defs>
<mask id="progress-as-mask" >
<rect width="100" height="100" fill="black"/>
<circle id="progress" cx="50" cy="50" r="47"
transform="rotate(-90 50 50)" pointer-events="all"
stroke="white" stroke-width="6" fill="none"/>
</mask>
</defs>
<circle id="grey" cx="50" cy="50" r="47"
transform="rotate(-90 50 50)"
stroke="#A9B0B7" stroke-width="4" fill="none"/>
<g mask="url(#progress-as-mask)">
<rect width="100" height="100" fill="#EB483F"/>
<circle id="pulse" cx="50" cy="50" r="47"
transform="rotate(-90 50 50)" pointer-events="all"
stroke="white" stroke-width="8" stroke-opacity="0.4" fill="none"/>
</g>
</svg>
You weren't entirely clear on what you wanted. But hopefully, this has at least got you started.
I'm trying to rotate a svg shape around its centre endlessly.
This is what I have so far.
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="841.89px" height="1190.55px" viewBox="0 0 841.89 1190.55" enable-background="new 0 0 841.89 1190.55"
xml:space="preserve">
<g>
<polygon fill="#E71320" points="530,771 453.936,713.721 487.465,802.842 430.618,726.453 437.681,821.41 404.659,732.1
384.683,825.2 378.16,730.205 332.763,813.906 353.268,720.921 286.129,788.442 332,705 248.558,750.871 316.079,683.732
223.094,704.236 306.795,658.84 211.799,652.317 304.9,632.342 215.59,599.319 310.547,606.382 234.158,549.536 323.279,583.064
266,507 342.064,564.279 308.536,475.158 365.382,551.547 358.319,456.59 391.341,545.9 411.317,452.799 417.84,547.795
463.236,464.094 442.732,557.079 509.871,489.558 464,573 547.442,527.129 479.921,594.268 572.906,573.763 489.205,619.16
584.2,625.683 491.1,645.658 580.41,678.682 485.453,671.618 561.842,728.465 472.721,694.936 " transform="rotate(15, 40, 40)" dur="0.1s" calcMode="discrete" repeatCount="indefinite"/>
<circle fill="none" stroke="#000000" stroke-width="10" stroke-miterlimit="10" cx="398" cy="639" r="39"/>
</g>
</svg>
…but can't get it to work.
Do I need to rotate it with javascript cause I think I've seen something similar using solely xml.
Also, the second shape should be in the centre of the first shape too.
Thanks for help!
Are you looking for something like this?
http://jsfiddle.net/t97w9cqm/7/
I'm just rotating it with CSS animations.
#Layer_1 {
transform-origin: 50% 50%;
-webkit-animation:spin 4s linear infinite;
-moz-animation:spin 4s linear infinite;
animation:spin 4s linear infinite;
}
#-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
#-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
#keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
The key is the transform-origin
You are missing the animation, add the animation and you should be set.
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="841.89px" height="1190.55px" viewBox="0 0 841.89 1190.55" enable-background="new 0 0 841.89 1190.55"
xml:space="preserve">
<g>
<polygon fill="#E71320" points="530,771 453.936,713.721 487.465,802.842 430.618,726.453 437.681,821.41 404.659,732.1
384.683,825.2 378.16,730.205 332.763,813.906 353.268,720.921 286.129,788.442 332,705 248.558,750.871 316.079,683.732
223.094,704.236 306.795,658.84 211.799,652.317 304.9,632.342 215.59,599.319 310.547,606.382 234.158,549.536 323.279,583.064
266,507 342.064,564.279 308.536,475.158 365.382,551.547 358.319,456.59 391.341,545.9 411.317,452.799 417.84,547.795
463.236,464.094 442.732,557.079 509.871,489.558 464,573 547.442,527.129 479.921,594.268 572.906,573.763 489.205,619.16
584.2,625.683 491.1,645.658 580.41,678.682 485.453,671.618 561.842,728.465 472.721,694.936" calcMode="discrete">
<animateTransform
attributeName="transform"
attributeType="XML"
type="rotate"
from="0 398 639"
to="360 398 639"
dur="1s"
repeatCount="indefinite"/>
</polygon>
<circle fill="none" stroke="#000000" stroke-width="10" stroke-miterlimit="10" cx="398" cy="639" r="39"/>
</g>
</svg>
Tested successfully in Chrome Version 46.0.2490.80 m on Windows 7. I have the 'star' spinning with the black ring toward the center of the star.