I have a class that change the color of a div and the fill of a svg, with a transition of 0.5s. But when I try it the transition on the fill was noticeable slower. I try to match it changing the transition of the element to 0.1469s. But its not perfect and kinda break the effect I was looking for.
.main-color{
background-color: var(--main-dark-color);
fill: var(--main-dark-color);
color: var(--main-light-color);
transition: all .5s;
}
.main-color.light {
background-color: var(--main-light-color);
fill: var(--main-light-color);
color: var(--main-dark-color);
}
.svg{
transition: all 0.1469s; /* This is the one running slower */
}
Any idea to fix this?
const swapColor = document.querySelectorAll(".main-color");
window.addEventListener("keydown", function(e) {
swapColor.forEach(el => {
el.classList.toggle("light");
})
});
.main-color {
fill: red;
background-color: blue;
transition: all 5s;
}
.main-color.light {
fill: blue;
background-color: red;
}
.parallax>use:nth-child(4) {
animation-delay: -5s;
animation-duration: 30s;
}
#keyframes move-forever {
0% {
transform: translate3d(-90px, 0, 0);
}
100% {
transform: translate3d(85px, 0, 0);
}
}
<div class="main-color">
<svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
<path x="1" y="7" id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
</svg>
</div>
Related
I added this map for the angular type script project, dose any one know to how to create bubble count region on the map like this image
Stack blitz here
here the jsFiddle code link
css here
p {font-size: 12px}
#core {
fill: #ff4f81;
animation: pulse1 1.5s ease-in-out infinite;
}
#radar {
fill: #F99EAD;
animation: pulse2 1.5s ease-in-out infinite;
}
#keyframes pulse1 {
0% {
opacity: 0;
transform: scale(0);
}
30% {
opacity: 1;
transform: scale(1.5);
}
60% {
opacity: 1;
transform: scale(2);
}
100% {
opacity: 0;
transform: scale(2);
}
}
#keyframes pulse2 {
0% {
transform: scale(1, 1);
opacity: 0;
}
50% {
opacity: 1;
}
100% {
transform: scale(6, 6);
opacity: 0;
}
}
.row-wrap {
text-align: center;
float: left;
margin: 0 10px;
}
.row-middle {
font-size: 30px;
color: #0E76FE;
font-weight: 700;
}
.row-middle-two{
font-size: 17px;color: #808490;
}
.row-middle-three{
font-size: 14px;color: #9DA2AE;
}
.row-bottom-small{
font-size: 10px; color: #B9C0CD;
}.row-top-small{
font-size: 10px;
color: #B9C0CD;
}
.row-bottom{
color: #A3A9B5;font-size: 12px;
}
.row-top{
color: #A3A9B5;font-size: 12px;
}
p {font-size: 12px}
So, to add an SVG bubble to your map (which is also SVG), you first need to pick the SVG file you'd like to add.
I chose the following (run the fiddle to see how it looks):
<?xml version="1.0" encoding="iso-8859-1"?>
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 293.334 293.334" style="enable-background:new 0 0 293.334 293.334;" xml:space="preserve">
<g>
<g>
<path style="fill:#010002;" d="M146.667,0C94.903,0,52.946,41.957,52.946,93.721c0,22.322,7.849,42.789,20.891,58.878
c4.204,5.178,11.237,13.331,14.903,18.906c21.109,32.069,48.19,78.643,56.082,116.864c1.354,6.527,2.986,6.641,4.743,0.212
c5.629-20.609,20.228-65.639,50.377-112.757c3.595-5.619,10.884-13.483,15.409-18.379c6.554-7.098,12.009-15.224,16.154-24.084
c5.651-12.086,8.882-25.466,8.882-39.629C240.387,41.962,198.43,0,146.667,0z M146.667,144.358
c-28.892,0-52.313-23.421-52.313-52.313c0-28.887,23.421-52.307,52.313-52.307s52.313,23.421,52.313,52.307
C198.98,120.938,175.559,144.358,146.667,144.358z"/>
<circle style="fill:#010002;" cx="146.667" cy="90.196" r="21.756"/>
</g>
</g>
</svg>
since you have already had everything set up beside the bubbles, and I didn't want to change it, I added a transform attribute to the <g> (so the bubble will be at the exact points and scale)
transform="translate(-64 -126) scale(0.5)"
To add it to the map, you just need to insert it in the location groups that you'd like and change the translate parameters so that it is in the right spot.
you can see it in work here (stackbitz)
I am following this codepen to create a dialog animation. But the animation doesn't seem to go smooth like the reference when I set the bigger dialog width and height. It seems like the issue is with svg stroke-dashoffset values but I am not sure what values do I need to set. Here is the codepen that I reproduced.
<div id="modal-close-default" class="" uk-modal>
<div class="uk-modal-dialog custom-modal six uk-modal-body lab-border-7 uk-margin-auto-vertical">
..
<svg class="modal-svg" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" preserveAspectRatio="none">
<rect x="0" y="0" fill="none" width="600" height="376" rx="3" ry="3"></rect>
</svg>
</div>
</div>
#modal-close-default {
.uk-modal-dialog.custom-modal {
..
}
.modal-svg {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
border-radius: 3px;
rect {
stroke: #fff;
stroke-width: 2px;
stroke-dasharray: 976; // total of dialog width and height (not sure what value to add)
stroke-dashoffset: 976;
}
}
&.uk-open>.uk-modal-dialog.custom-modal {
..
.modal-svg {
rect {
animation: sketchIn .5s .3s cubic-bezier(0.165, 0.840, 0.440, 1.000) forwards; // animation is not smooth
}
}
}
}
#keyframes sketchIn {
0% {
stroke-dashoffset: 976;
}
100% {
stroke-dashoffset: 0;
}
}
You miscalculated the length of the perimeter of the rectangle
If it's rough, then you need to consider this (width +height) * 2 = 1952px
The JS method getTotalLength() will help you calculate exactly the perimeter, taking into account the roundings.
Happened with rounding ~= 1946px
.modal-svg {
position: absolute;
top: 0;
left: 0;
border-radius: 3px;
}
rect {
stroke: silver;
stroke-width: 6px;
stroke-dasharray: 1946; // total of dialog width and height (not sure what value to add)
stroke-dashoffset: 1946;
animation: sketchIn 5s .3s cubic-bezier(0.165, 0.840, 0.440, 1.000) forwards; // animation is not smooth
}
#keyframes sketchIn {
0% {
stroke-dashoffset: 1946;
}
100% {
stroke-dashoffset: 0;
}
}
<div id="modal-close-default" class="uk-modal">
<div class="uk-modal-dialog custom-modal six uk-modal-body lab-border-7 uk-margin-auto-vertical">
<svg class="modal-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 376" width="600" height="376" >
<rect id="rect" x="0" y="0" fill="none" width="600" height="376" rx="3" ry="3"></rect>
</svg>
</div>
</div>
<script>
let total = rect.getTotalLength();
console.log(total)
</script>
I wrote something like this:
<svg class="svg-cab" height="35px" width="35px" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 202 228.7">
<defs><style>
.cls-21{
fill:white;
cursor: pointer; }
.svg-cab:hover .cls-21{
stroke-dasharray: 1000;stroke-miterlimit:10;stroke-width:20px;
stroke-dashoffset: 1000;
animation: dash 1s linear;
stroke: white;
}
#keyframes dash {
from {
stroke-dashoffset: 999;
}
to {
stroke-dashoffset: 0;
}
}
</style></defs><path class="cls-21" d="M277.3,192.9a53.3,53.3,0,1,1-51.6-51.5A53.3,53.3,0,0,1,277.3,192.9Z" transform="translate(-123 -136.3)"/><path class="cls-21" d="M269.3,264H178.7A50.7,50.7,0,0,0,128,314.7V352a8,8,0,0,0,8,8H312a8,8,0,0,0,8-8V314.7A50.7,50.7,0,0,0,269.3,264Z" transform="translate(-123 -136.3)"/></svg></a>
It s an animation when I hover on the svg the stroke looms over it
and I need to when animation has been ended the stroke was saved till mouseover
Does anyone have any idea?
You can rely on forwards and animation-play-state to simulate this. The trick is to move all the style that you need to keep inside an animation and forwards will do the job of saving them
.cls-21 {
fill: red;
cursor: pointer;
animation:
dash 1s linear paused forwards,
stroke 1s linear paused forwards;
}
.svg-cab:hover .cls-21 {
stroke-dasharray: 1000;
stroke-miterlimit: 10;
animation-play-state: running;
}
#keyframes dash {
from {
stroke-dashoffset: 999;
}
to {
stroke-dashoffset: 0;
}
}
#keyframes stroke {
1%,100% {
stroke: white;
stroke-width: 20px;
}
}
<svg class="svg-cab" height="35px" width="35px" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 202 228.7">
<path class="cls-21" d="M277.3,192.9a53.3,53.3,0,1,1-51.6-51.5A53.3,53.3,0,0,1,277.3,192.9Z" transform="translate(-123 -136.3)"/><path class="cls-21" d="M269.3,264H178.7A50.7,50.7,0,0,0,128,314.7V352a8,8,0,0,0,8,8H312a8,8,0,0,0,8-8V314.7A50.7,50.7,0,0,0,269.3,264Z" transform="translate(-123 -136.3)"/></svg>
I am using a checkbox in my html project. I have taken the reference from this link.
https://codepen.io/andreasstorm/pen/deRvMy.
When the checkbox is checked the svg animation is perfectly fine. But when I unchecked the checkbox there is no animation. How can I make the reverse animation while unchecking the checkbox by using the same animation from default to checked. Please help.
<div class="radiocheckcontainer">
<input type="checkbox" id="cbx" />
<label for="cbx" class="check">
<svg width="18px" height="18px" viewBox="0 0 18 18">
<path d="M1,9 L1,3.5 C1,2 2,1 3.5,1 L14.5,1 C16,1 17,2 17,3.5 L17,14.5 C17,16 16,17 14.5,17 L3.5,17 C2,17 1,16 1,14.5 L1,9 Z"></path>
<polyline points="1 9 7 14 15 4"></polyline>
</svg>
<span>remember me</span>
</label>
.radiocheckcontainer input{
display: none;
}
.check {
cursor: pointer;
position: relative;
margin: 0 auto;
-webkit-tap-highlight-color: transparent;
transform: translate3d(0, 0, 0);
}
.check svg {
position: relative;
z-index: 1;
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
stroke: #D8DAE6;
stroke-width: 1;
transform: translate3d(0, 0, 0);
transition: all 0.2s ease-in-out;
display: inline-block;
vertical-align: middle;
width: 20px;
height: 20px;
}
.check svg path {
stroke-dasharray: 60;
stroke-dashoffset: 0;
}
.check svg polyline {
stroke-dasharray: 22;
stroke-dashoffset: 66;
}
.check:hover svg {
stroke: #073AAB;
}
#cbx:checked + .check svg {
stroke: #073AAB;
}
#cbx:checked + .check svg path {
stroke-dashoffset: 60;
transition: all 0.3s linear;
}
#cbx:checked + .check svg polyline {
stroke-dashoffset: 42;
transition: all 0.2s linear;
transition-delay: 0.15s;
}
.radiocheckcontainer label span{
font-weight: normal;
font-size: 0.875rem;
color: #B7B9CB;
text-transform: capitalize;
display: inline-block;
vertical-align: middle;
margin-left: 10px;
}
That's because the path and polyline elements in the unchecked state does not have any transitions attached to it: therefore, you don't see any transition when reverting to the unchecked state.
If you declare the same transition properties to the unchecked state, and simply move the transition-delay to the path, it should work as expected:
.check
svg
path
stroke-dasharray: 60
stroke-dashoffset: 0
transition: all .3s linear // Add this line
transition-delay: .15s // Add this line
polyline
stroke-dasharray: 22
stroke-dashoffset: 66
transition: all .2s linear // Add this line
See proof-of-concept here: https://codepen.io/terrymun/pen/NWGoezb
I'm working on making a simple loading spinner element with SVG. It works excellently in Chrome, but not in other browsers. In IE, the animation doesn't work at all. More troubling, in FF, the animation works but the rotation is not centered at the right location.
What can I do to make it rotate correctly in FF? (Edit: It actually works correctly in FF 42alpha.) Is there anything I can do to get it to work in IE? (Targeting the current version of these browsers)
The snippet below contains the relevant CSS and HTML:
svg.spinner {
display: block;
width: 50px;
}
svg.spinner path {
fill-opacity: 0;
stroke-width: 11;
}
svg.spinner path.track {
stroke: rgba(92, 112, 128, 0.2);
}
svg.spinner path.head {
stroke: rgba(92, 112, 128, 0.5);
stroke-linecap: round;
/* -webkit-transform-origin: 50px 50px; */
-ms-transform-origin: 50px 50px;
transform-origin: 50px 50px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<svg class="spinner" viewBox="0 0 100 100">
<path class="track" d="M 50,50 m 0,-44.5 a 44.5,44.5 0 1 1 0,89 a 44.5,44.5 0 1 1 0,-89"></path>
<path class="head" d="M 91.81632162497291 65.21989637799226 A 44.5 44.5 0 0 0 50 5.5"></path>
</svg>
Newer versions of FF handle this more appropriately. Firefox 41 and up adds proper support for transform-origin with regards to SVG elements. It also adds the transform-box property. You can set this to view-box and it will use the SVG viewbox as a reference and correctly calculate the transform origin. FF 40 and older seem to calculate the position of the transform origin relative to the path element in question by default, and don't support any way to change this.
So good news for the future! However, this does not help with getting things working on the current version of FF or on IE.
This answer works on Firefox 40, Firefox 42 and Chrome.
svg.spinner {
display: block;
width: 50px;
}
svg.spinner path {
fill-opacity: 0;
stroke-width: 11;
}
svg.spinner path.track {
stroke: rgba(92, 112, 128, 0.2);
}
svg.spinner path.head {
stroke: rgba(92, 112, 128, 0.5);
stroke-linecap: round;
-ms-transform-origin: 50px 50px;
transform-origin: 50px 50px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<svg class="spinner" viewBox="-50 -50 100 100">
<g transform="translate(-50, -50)" >
<path class="track" d="M 50,50 m 0,-44.5 a 44.5,44.5 0 1 1 0,89 a 44.5,44.5 0 1 1 0,-89"></path>
<path class="head" d="M 91.81632162497291 65.21989637799226 A 44.5 44.5 0 0 0 50 5.5"></path>
</g>
</svg>
From #JKillian's answer there seem to be no way to fix it for older browsers.
There is another way to animate the element. :D
Im drawing to circle. No fill only stroke.
And animating the stroke to get the desired effect.
svg.spinner {
display: block;
width: 150px;
}
.circ {
fill: none;
stroke: #222;
stroke-width: 10;
}
#circ2 {
stroke: #999;
stroke-dasharray: 160, 100;
stroke-dashoffset: 0;
transition: stroke-dashoffset 2s;
}
svg:hover #circ2 {
stroke-dashoffset: 500;
}
<svg class="spinner" viewBox="0 0 100 100">
<circle class="circ" id="circ1" cx="50" cy="50" r="41" />
<circle class="circ" id="circ2" cx="50" cy="50" r="41" />
</svg>