Custom Checkbox animation on check and uncheck: CSS - css

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

Related

CSS Transition run slower on fill

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>

CSS3 Simple Transition with SVG: appearing and disappearing on mouse :hover

I am trying to make a simple css3 transition work with two items: an svg box (representing an svg drawn logo) and a <p> tag (representing a title name tag) behind it.
By default only the box should show and the text should be hidden. When the mouse hovers over the svg box, the box should dissappear with a simple css fade transition (or even better shadow blur for bonus points ;-) and then the name title should appear to focus (from shadowy blurr) all in say 1 second.
At the moment I'm stuck here since my code is broken to activate the mouse hover. What am i doing wrong at this stage? Isn't svg:hover p the correct selector for my last move? And how to set the transition fade effects? Thanks!
// UPDATED code with the Answer in snippet
* {margin: 0; padding: 0;}
.svg-container * {
-webkit-transition: all 1000ms ease;
-moz-transition: all 1000ms ease;
-o-transition: all 1000ms ease;
-ms-transition: all 1000ms ease;
transition: all 1000ms ease;
}
svg {
position: absolute;
fill: rgba(0, 200, 0, 1);
z-index: 2;
top: 0;
left: 0;
display: block;
opacity: 1;
}
p {
position: absolute;
z-index: 1;
top:70px;
display: block;
color: rgba(0,0,200,0);
}
.svg-container:hover svg {
opacity: 0;
}
.svg-container:hover p {
color: rgba(0,0,200,1);
}
<div class="svg-container">
<svg width="100" height="100" viewBox="0 0 100 100">
<rect x="10" y="10" width="100" height="100"/>
</svg>
<p>Title of this Website</p>
</div>
You can't place elements inside the SVG.
You should place both SVG and paragraph inside a container, and set the hover effect to act on the container.
For the transition, use the transition property on each element, or just place it on all child elements of the parent.
Something like this:
<style type="text/css">
* {margin: 0; padding: 0;}
.svg-container * {
-webkit-transition: all 1000ms ease;
-moz-transition: all 1000ms ease;
-o-transition: all 1000ms ease;
-ms-transition: all 1000ms ease;
transition: all 1000ms ease;
}
svg {
position: absolute;
fill: rgba(0, 200, 0, 1);
z-index: 2;
top: 0;
left: 0;
display: block;
opacity: 1;
}
p {
position: absolute;
z-index: 1;
top:70px;
display: block;
color: rgba(0,0,200,0);
}
.svg-container:hover svg {
opacity: 0;
}
.svg-container:hover p {
color: rgba(0,0,200,1);
}
</style>
<div class="svg-container">
<svg width="100" height="100" viewBox="0 0 100 100">
<rect x="10" y="10" width="100" height="100"/>
</svg>
<p>Title of this Website</p>
</div>

I'm having trouble controlling an animated svg border using CSS

I've been trying to animate a svg border, I've gotten as far as this
html {
background: white;
}
div {
position: fixed;
height: 200px;
width: 605px;
position: fixed;
left: 30%
}
.mainNav {
position: fixed;
top: 6;
}
[class="navBorder"] .outline {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
stroke: #7272f8;
stroke-width: 11px;
fill: none;
}
.navBorder .outline {
stroke-dasharray: 2000;
stroke-dashoffset: 1900;
-webkit-transition: 0.5s;
-moz-transition: 0.5s;
-o-transition: 0.5s;
transition: 0.5s;
}
.navBorder:hover .outline {
stroke-dasharray: 1100 0;
stroke-dashoffset: 0;
}
<div>
<a class="navBorder" target="_blank">
<svg height="100%" width="100%" xmlns="http://www.w3.org/2000/svg">
<rect class="outline" height="100%" width="100%" />
</svg>
</a>
</div>
http://codepen.io/lorehill/pen/pEPXar
The problem is I can't seem to get the starting position of the border to be on the top center and then close center bottom.
I'm very confused trying to figure out how to calculate the values I need to set stroke-dasharray and stroke-dashoffset for the starting position in order to get the effect I'm after.
If anyone could explain it like I'm 5 that would be fantastic.
Thank you!
AFAIK, the starting position of the stroke is always the starting point of the rect which is top left for a rect element.
I can't seem to get the starting position of the border to be on the top center and then close center bottom.
I think you'll need two polyline elements for that, although you can use the same class on both.
svg {
height: 100px;
margin: 1em;
}
.outline {
fill: lightblue;
stroke-dasharray: 200;
stroke-dashoffset: 190;
-webkit-transition: 0.5s;
-moz-transition: 0.5s;
-o-transition: 0.5s;
transition: 0.5s;
}
svg:hover .outline {
stroke-dasharray: 200 0;
stroke-dashoffset: 0;
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewbox="0 0 100 100">
<polyline class="outline" points="50,0 100,0, 100,100 50,100" style="stroke:#660000; stroke-width: 3;" />
<polyline class="outline" points="50,0 0,0 0,100 50,100" style="stroke:#660000; stroke-width: 3;" />
</svg>
Codepen Demo

Modern google loader not working in IE

I've been trying to find a modern google loader which is cross browser.
Can anyone please help me find one, i found this one which works for all except Internet Explorer, or maybe tell me how i can get this one to work in IE ?
I tried fakesmile but it didnt work.
HTML :
<div class="loader">
<svg class="circular">
<circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" />
</svg>
</div>
CSS :
.loader {
position: relative;
margin: 0px auto;
width: 100px;
height: 100px;
zoom: 1;
}
.circular {
animation: rotate 1s linear infinite;
height: 100px;
position: relative;
width: 100px;
}
.path {
stroke: gray;
stroke-dasharray: 1,200;
stroke-dashoffset: 0;
animation: dash 1.5s ease-in-out infinite;
stroke-linecap: round;
}
#keyframes rotate {
100% {
transform: rotate(360deg);
}
}
#keyframes dash {
0% {
stroke-dasharray: 1,200;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 89,200;
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: 89,200;
stroke-dashoffset: -124;
}
}
Older versions of IE do not support the keyframes, i left IE behind.

CSS3 Donut Chart

I have created a fiddle of a simple donut chart: http://jsfiddle.net/4azpfk3r/217/
How can i get the donut chart to have a red outline and the score/percentage filled to be solid red leaving a transparent/red outlined section of percentage not scored?
CSS:
.background {
background: grey;
}
.item {
position: relative;
float: left;
}
.item h2 {
text-align:center;
position: absolute;
line-height: 125px;
width: 100%;
}
svg {
transform: rotate(-90deg);
}
.circle_animation {
stroke-dasharray: 440;
stroke-dashoffset: 440;
}
.html .circle_animation {
-webkit-animation: html 1s ease-out forwards;
animation: html 1s ease-out forwards;
}
.css .circle_animation {
-webkit-animation: css 1s ease-out forwards;
animation: css 1s ease-out forwards;
}
#-webkit-keyframes html {
to {
stroke-dashoffset: 80;
}
}
#keyframes html {
to {
stroke-dashoffset: 80;
}
}
If I am understanding your problem correctly, try adding this line of css:
#circle{fill:none;stroke:red;color:red}
For the score type to also be in red, add a color property to the h2:
.item h2 {
text-align:center;
position: absolute;
line-height: 125px;
width: 100%;
color:red; /*ADD RED COLOR TO SCORE*/
}
To style the Score header, first give it a class:
<p class="scoreHeader">Score: 76/100</p>
And style it as you wish:
.scoreHeader{
padding:10px;
background:red;
color:white;
font-weight:bold;
}
Check my example here https://codepen.io/350d/pen/gxXyGB
The idea is to utilize just a border-color and rotation. No gradients and animations used here.

Resources