I'm trying to get animation effect on every click on button it works well on desktop but I'm getting problem to do the same on phone. I have to click on button once and then somewhere empty to lose focus state of css then click on button again to get the animation effect.
here is code snippet.
.btn_container {
color: #35f8ff;
position: relative;
display: inline-block;
text-align: center;
margin: 2.5rem auto;
}
.prog_btn {
text-transform: uppercase;
font-size: 1.3rem;
padding: 10px 25px;
z-index: 3;
background-color: transparent;
cursor: pointer;
transition: 0.2s ease-out;
position: relative;
margin: auto;
}
.btn_container .svgStroke {
position: absolute;
z-index: 1;
width: 100%;
top: -25%;
left: 0;
}
.btn_container .svgStroke path {
stroke-dasharray: 100;
stroke-dashoffset: -800;
stroke-width: 2;
transition: all 1s ease-in-out;
stroke: #35f8ff;
}
#keyframes dash {
0% {
stroke-dasharray: 100;
stroke-width: 2;
}
50% {
stroke-width: 4;
stroke: #35f8ff;
filter: drop-shadow(0px 0px 3px #e8615a) drop-shadow(0px 0px 20px #35f8ff) drop-shadow(0px 0px 150px #35f8ff);
}
100% {
stroke-dashoffset: 800;
stroke-width: 2;
}
}
.prog_btn:hover+.svgStroke path {
cursor: pointer;
animation: dash 1.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.prog_btn:hover {
font-size: 1.2rem;
}
.add {
display: inline-block;
margin-right: 0.75rem;
height: 1.5rem;
width: 1.5rem;
}
<div class="btn_container">
<div class="prog_btn">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="add">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 4.5v15m7.5-7.5h-15"
></path>
</svg> Add 10%
</div>
<svg class="svgStroke" width="222" height="65" viewBox="0 0 222 85" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M205 84H21L1 63.4941V18.5765L21 1H205L221 18.5765V63.4941L205 84Z"
stroke="white"
stroke-width="2"
></path>
</svg>
</div>
here is codepen link too.
I was hoping to be able to unset focus (ie blur) at animation end but this did not work.
Here is a slightly clumsy workaround - this snippet removes the animation when it has come to an end and sets it back when there is another touchstart. It uses style setting rather than classes.
let touchDevice = false;
const progBtn = document.querySelector('.prog_btn');
const path = document.querySelector('.prog_btn +.svgStroke path');
path.addEventListener('animationend', function() {
path.style.animation = '';
});
progBtn.addEventListener('touchstart', function() {
touchDevice = true;
path.style.animation = 'dash 1.5s cubic-bezier(0.25, 0.46, 0.45, 0.94)';
});
progBtn.addEventListener('mouseover', function() {
path.style.animation = 'dash 1.5s cubic-bezier(0.25, 0.46, 0.45, 0.94)';
});
.btn_container {
color: #35f8ff;
position: relative;
display: inline-block;
text-align: center;
margin: 2.5rem auto;
}
.prog_btn {
text-transform: uppercase;
font-size: 1.3rem;
padding: 10px 25px;
z-index: 3;
background-color: transparent;
cursor: pointer;
transition: 0.2s ease-out;
position: relative;
margin: auto;
}
.btn_container .svgStroke {
position: absolute;
z-index: 1;
width: 100%;
top: -25%;
left: 0;
}
.btn_container .svgStroke path {
stroke-dasharray: 100;
stroke-dashoffset: -800;
stroke-width: 2;
transition: all 1s ease-in-out;
stroke: #35f8ff;
}
#keyframes dash {
0% {
stroke-dasharray: 100;
stroke-width: 2;
}
50% {
stroke-width: 4;
stroke: #35f8ff;
filter: drop-shadow(0px 0px 3px #e8615a) drop-shadow(0px 0px 20px #35f8ff) drop-shadow(0px 0px 150px #35f8ff);
}
100% {
stroke-dashoffset: 800;
stroke-width: 2;
}
}
.prog_btn:hover+.svgStroke path {
cursor: pointer;
}
.prog_btn:hover {
font-size: 1.2rem;
}
.add {
display: inline-block;
margin-right: 0.75rem;
height: 1.5rem;
width: 1.5rem;
}
<div class="btn_container">
<div class="prog_btn">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="add">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 4.5v15m7.5-7.5h-15"
></path>
</svg> Add 10%
</div>
<svg class="svgStroke" width="222" height="65" viewBox="0 0 222 85" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M205 84H21L1 63.4941V18.5765L21 1H205L221 18.5765V63.4941L205 84Z"
stroke="white"
stroke-width="2"
></path>
</svg>
</div>
Here the demo: https://codepen.io/joondoe/pen/XWrGgyo
here the code:
html, body {
height: 100%;
}
body {
background: #082330;
background-size: .12em 100%;
font: 16em/1 Arial;
}
h1 {
font-size: 0.15em;
margin: 30px;
font-family: Mansalva;
}
.text--line {
font-size: .5em;
}
svg {
position: absolute;
width: 100%;
height: 100%;
}
.text-copy {
fill: none;
stroke: white;
stroke-dasharray: 7% 28%;
stroke-width: 9px;
font-family: Mansalva;
-webkit-animation: stroke-offset 5s infinite linear;
animation: stroke-offset 5s infinite linear;
}
.text-copy:nth-child(1) {
stroke: #360745;
stroke-dashoffset: 7%;
}
.text-copy:nth-child(2) {
stroke: #D61C59;
stroke-dashoffset: 14%;
}
.text-copy:nth-child(3) {
stroke: #E7D84B;
stroke-dashoffset: 21%;
}
.text-copy:nth-child(4) {
stroke: #EFEAC5;
stroke-dashoffset: 28%;
}
.text-copy:nth-child(5) {
stroke: #1B8798;
stroke-dashoffset: 35%;
}
#-webkit-keyframes stroke-offset {
50% {
stroke-dashoffset: 35%;
stroke-dasharray: 0 87.5%;
}
}
#keyframes stroke-offset {
50% {
stroke-dashoffset: 35%;
stroke-dasharray: 0 87.5%;
}
}
<link href="https://fonts.googleapis.com/css?family=Dancing+Script|Mansalva&display=swap" rel="stylesheet">
<h1> Hey World </h1>
<svg viewBox="0 0 800 600">
<symbol id="s-text">
<text text-anchor="middle"
x="50%"
y="35%"
class="text--line"
>
Hey
</text>
<text text-anchor="middle"
x="50%"
y="68%"
class="text--line2"
>
World
</text>
</symbol>
<g class="g-ants">
<use xlink:href="#s-text"
class="text-copy"></use>
<use xlink:href="#s-text"
class="text-copy"></use>
<use xlink:href="#s-text"
class="text-copy"></use>
<use xlink:href="#s-text"
class="text-copy"></use>
<use xlink:href="#s-text"
class="text-copy"></use>
</g>
</svg>
I am wondering why the middle stroke of the "W"'s letter is very sharp in "Hey World" since it is very smooth in the original font -see the text.
thanks for any hint
It looks like pointy line join is not noticeable on the font because it is hidden by the font being filled in where your animated outline is not.
If you want to change it though see the stroke-linejoin attribute.
I have a header on the left side and want to add a button inline with the header on the right side.
When I add "position:relative: and top:400px, it moves the button perfectly. When i add "left:200px" it moves the button perfectly again, but when i hover it moves the button back to center of page.
How do i stop it from doing this?
i've created IMG images to show specifically how it moves:
https://imgur.com/a/SMLCbmN
**note when left:200px; is not added, the button doesn't move to center of page. i've tried removing the "text-algin: center;" along with a lot of other ideas..but am stuck.
Here is the code: https://codepen.io/TheGreatEscape/pen/ebYgGO
.container {
width: 100%;
text-align: center;
margin-top: 0vh;
}
.circle {
stroke: #f70f4d;
stroke-dasharray: 650;
stroke-dashoffset: 650;
-webkit-transition: all 0.5s ease-in-out;
opacity: 0.3;
}
.playBut {
position: relative;
top: 400px;
left: 200px;
border: none;
-webkit-transition: all 0.5s ease;
}
.playBut .triangle {
-webkit-transition: all 0.7s ease-in-out;
stroke-dasharray: 240;
stroke-dashoffset: 480;
stroke: #000;
transform: translateY(0);
}
.playBut:hover .triangle {
stroke-dashoffset: 0;
opacity: 1;
stroke: #f70f4d;
animation: nudge 0.7s ease-in-out;
}
#keyframes nudge {
0% {
transform: translateX(0);
}
30% {
transform: translateX(-5px);
}
50% {
transform: translateX(5px);
}
70% {
transform: translateX(-2px);
}
100% {
transform: translateX(0);
}
}
.playBut:hover .circle {
stroke-dashoffset: 0;
opacity: 1;
}
<div class='container'>
<a href='#' class='playBut'>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" x="0px" y="0px" width="213.7px" height="213.7px" viewBox="0 0 213.7 213.7" enable-background="new 0 0 213.7 213.7"
xml:space="preserve">
<polygon class='triangle' id="XMLID_18_" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="
73.5,62.5 148.5,105.8 73.5,149.1 "/>
<circle class='circle' id="XMLID_17_" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" cx="106.8" cy="106.8" r="103.3"/>
</svg>
</a>
</div>
see this demo if it helps
/*===== PLAY BUTTON ===*/
.container {
width: 100%;
text-align: center;
margin-top: 0vh;
}
.circle {
stroke: #f70f4d;
stroke-dasharray: 650;
stroke-dashoffset: 650;
-webkit-transition: all 0.5s ease-in-out;
opacity: 0.3;
}
.playBut {
/*position: relative;
top:400px;
left:200px;*/
border: none;
-webkit-transition: all 0.5s ease;
}
.playBut .triangle {
-webkit-transition: all 0.7s ease-in-out;
stroke-dasharray: 240;
stroke-dashoffset: 480;
stroke: #000;
transform: translateY(0);
}
.playBut:hover .triangle {
stroke-dashoffset: 0;
opacity: 1;
stroke: #f70f4d;
animation: nudge 0.7s ease-in-out;
}
#keyframes nudge {
0% {
transform: translateX(0);
}
30% {
transform: translateX(-5px);
}
50% {
transform: translateX(5px);
}
70% {
transform: translateX(-2px);
}
100% {
transform: translateX(0);
}
}
.playBut:hover .circle {
stroke-dashoffset: 0;
opacity: 1;
}
h2.title {
font-size: 40px;
margin: 60px 0 0;
display: inline-block;
float: left;
}
<div class='container'>
<h2 class="title">some text</h2>
<a href='#'class='playBut'>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In -->
<svg version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
x="0px" y="0px" width="213.7px" height="213.7px" viewBox="0 0 213.7 213.7" enable-background="new 0 0 213.7 213.7"
xml:space="preserve">
<polygon class='triangle' id="XMLID_18_" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="
73.5,62.5 148.5,105.8 73.5,149.1 "/>
<circle class='circle' id="XMLID_17_" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" cx="106.8" cy="106.8" r="103.3"/>
</svg>
</a>
</div>
Update
you need
a.playBut, a.playBut:hover, a.playBut:active, a.playBut:focus {
left: 800px;
right: auto;
}
see demo
normal
on hover
Add position: absolute to your .playBut. top and left works only on absolute position.
See example here
I am trying to add the CSS code inside the HTML but I am having trouble getting the SVG animation to work. What am I doing wrong here? My guest is that I am referencing <style> wrongly but after a couple of tries I can't make it work.
<svg>
<style type="text/css">
.spinner {
animation: rotate 2s linear infinite;
z-index: 2;
position: absolute;
top: 50%;
left: 50%;
margin: -25px 0 0 -25px;
width: 50px;
height: 50px;
}
.path {
stroke: hsl(210, 70, 75);
stroke-linecap: round;
animation: dash 1.5s ease-in-out infinite;
}
#keyframes rotate {
100% {
transform: rotate(360deg);
}
}
#keyframes dash {
0% {
stroke-dasharray: 1, 150;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -124;
}
}
</style>
<svg class="spinner">
<circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="5"</circle>
</svg>
</svg>
CodePen
Thank you in advance.
Your animation works. You messed up stroke color definition. hsl(210, 70%, 75%);
and circle elements opening tag is missing closing bracket >
<circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="5" > </circle>
html, body {
height: 100%;
background-color: #000000;
}
<svg>
<style type="text/css">
.spinner {
animation: rotate 2s linear infinite;
transform-origin:center center;
z-index: 2;
position: absolute;
top: 50%;
left: 50%;
margin: -25px 0 0 -25px;
width: 50px;
height: 50px;
}
.path {
stroke: hsl(210, 70%, 75%);
stroke-linecap: round;
animation: dash 1.5s ease-in-out infinite;
}
#keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
#keyframes dash {
0% {
stroke-dasharray: 1, 150;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -124;
}
}
</style>
<g class="spinner">
<circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="5"></circle>
</g>
</svg>
you need to close the html tag for circle
<circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="5"</circle>
should be
<circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="5"></circle>
So I made a bunch of edits to an SVG file and now I can't open in in AI and it will not display on web. I'm guessing it is due to the fact that I have HTML elements inside it like the tags but I am not sure how to get around that without breaking the rest of the code.
<div>
<div id="banner">
<div>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="300px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve">
<defs>
<clipPath id="drop">
<path transform="scale(0.75), translate(32,0)" d="M68.2,6.7c0,0-62.4,70.9-62.4,124.7c0,32.3,28,58.4,62.4,58.4s62.4-26.2,62.4-58.4
C130.7,77.6,68.3,6.7,68.2,6.7z M61,77.5c0.8,0,1.5,0.7,1.5,1.5v20.6c2.7-3.6,7.6-5.7,13.1-5.7c12.2,0,19.4,6.9,19.4,18.7v37.2
c0,0.8-0.7,1.5-1.5,1.5H75.6c-0.8,0-1.5-0.7-1.4-1.5v-32c0-4.1-1.8-6.4-5-6.4c-5.8,0-6.7,5.7-6.7,5.7v32.7c0,0.8-0.7,1.5-1.5,1.5
H43.1c-0.8,0-1.5-0.7-1.5-1.5V79c0-0.8,0.7-1.5,1.5-1.5H61z" />
</clipPath>
</defs>
<g clip-path="url(#drop)">
<g class="fill">
<path fill="#04ACFF" id="waveShape" d="M300,300V2.5c0,0-0.6-0.1-1.1-0.1c0,0-25.5-2.3-40.5-2.4c-15,0-40.6,2.4-40.6,2.4
c-12.3,1.1-30.3,1.8-31.9,1.9c-2-0.1-19.7-0.8-32-1.9c0,0-25.8-2.3-40.8-2.4c-15,0-40.8,2.4-40.8,2.4c-12.3,1.1-30.4,1.8-32,1.9
c-2-0.1-20-0.8-32.2-1.9c0,0-3.1-0.3-8.1-0.7V300H300z" />
</g>
</g>
<g transform="scale(0.75), translate(32,0)">
<path class="st0" d="M68.2,6.7c0,0-62.4,70.9-62.4,124.7c0,32.3,28,58.4,62.4,58.4s62.4-26.2,62.4-58.4
C130.7,77.6,68.3,6.7,68.2,6.7z" />
<path class="st1" d="M61,77.5c0.8,0,1.5,0.7,1.5,1.5v20.6c2.7-3.6,7.6-5.7,13.1-5.7c12.2,0,19.4,6.9,19.4,18.7v37.2
c0,0.8-0.7,1.5-1.5,1.5H75.6c-0.8,0-1.5-0.7-1.4-1.5v-32c0-4.1-1.8-6.4-5-6.4c-5.8,0-6.7,5.7-6.7,5.7v32.7c0,0.8-0.7,1.5-1.5,1.5
H43.1c-0.8,0-1.5-0.7-1.5-1.5V79c0-0.8,0.7-1.5,1.5-1.5H61z" />
</g>
<defs>
<style type="text/css">
.st0 {
fill: none;
stroke: #000;
stroke-width: 4;
stroke-miterlimit: 5;
}
.st1 {
fill: none;
stroke: #fff;
stroke-width: 3;
stroke-miterlimit: 5;
}
#banner {
border-radius: 50%;
width: 150px;
height: 150px;
background: #fff;
overflow: hidden;
backface-visibility: hidden;
transform: translate3d(0, 0, 0);
}
#banner .fill {
animation-name: fillAction;
animation-iteration-count: 1;
animation-timing-function: cubic-bezier(.2, .6, .8, .4);
animation-duration: 4s;
animation-fill-mode: forwards;
}
#banner #waveShape {
animation-name: waveAction;
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-duration: 0.5s;
width: 300px;
height: 150px;
fill: #04ACFF;
}
#keyframes fillAction {
0% {
transform: translate(0, 150px);
}
100% {
transform: translate(0, -5px);
}
}
#keyframes waveAction {
0% {
transform: translate(-150px, 0);
}
100% {
transform: translate(0, 0);
}
}
</style>
</defs>
</svg>
</div>
</div>
</div>