I have a heart button when onclick it will fill the SVG with red from bottom to top and when unclicked it will unfill the SVG from top to bottom. Heres what I've searched so far:JSFiddle
I'm new with this kind of techniques like keyframes and clip-path thing. These can all be done via css only?
body {
display: -webkit-box;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
height: 100vh;
}
.heart-container {
position: relative;
width: 40px;
height: 40px;
}
.heart-clip {
display: block;
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
-webkit-clip-path: url(#svgPath);
clip-path: url(#svgPath);
}
.heart-clip:hover {
-webkit-animation: pulse .6s .3s infinite;
animation: pulse .6s .3s infinite;
}
.heart-clip:hover::before {
-webkit-transform: scale(1);
transform: scale(1);
opacity: 1;
}
.heart-clip::before {
content: '';
display: block;
width: 100%;
height: 100%;
border-radius: 50%;
background-color: #D32F2F;
opacity: 0;
-webkit-transform: scale(0);
transform: scale(0);
-webkit-transition: opacity .2s linear, -webkit-transform .2s linear;
transition: opacity .2s linear, -webkit-transform .2s linear;
transition: transform .2s linear, opacity .2s linear;
transition: transform .2s linear, opacity .2s linear, -webkit-transform .2s linear;
-webkit-transform-origin: center 60%;
transform-origin: center 60%;
}
.heart-stroke {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
fill: #D32F2F;
}
#-webkit-keyframes pulse {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
30% {
-webkit-transform: scale(1.2);
transform: scale(1.2);
}
60% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
#keyframes pulse {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
30% {
-webkit-transform: scale(1.2);
transform: scale(1.2);
}
60% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
<svg height="0" width="0">
<defs>
<clipPath id="svgPath">
<path d="M20,35.09,4.55,19.64a8.5,8.5,0,0,1-.13-12l.13-.13a8.72,8.72,0,0,1,12.14,0L20,10.79l3.3-3.3a8.09,8.09,0,0,1,5.83-2.58,8.89,8.89,0,0,1,6.31,2.58,8.5,8.5,0,0,1,.13,12l-.13.13Z"/>
</clipPath>
</defs>
</svg>
<div class="heart-container">
<svg width="40" height="40" viewBox="0 0 40 40" class='heart-stroke'>
<path d="M20,35.07,4.55,19.62a8.5,8.5,0,0,1-.12-12l.12-.12a8.72,8.72,0,0,1,12.14,0L20,10.77l3.3-3.3A8.09,8.09,0,0,1,29.13,4.9a8.89,8.89,0,0,1,6.31,2.58,8.5,8.5,0,0,1,.12,12l-.12.12ZM10.64,7.13A6.44,6.44,0,0,0,6.07,18.19L20,32.06,33.94,18.12A6.44,6.44,0,0,0,34,9l0,0a6.44,6.44,0,0,0-4.77-1.85A6,6,0,0,0,24.83,9L20,13.78,15.21,9A6.44,6.44,0,0,0,10.64,7.13Z"/>
</svg>
<a href='#' class='heart-clip'></a>
</div>
any alternatives and solutions is much appreciated!
Thanks in advance!
Consider filling with color using the feFlood filters and animating with changing thedy attribute of the feoffset filter.
Repeated clicks change the color direction animation
var svg1 = document.getElementById("svg1"),
close = document.getElementById('close'),
open = document.getElementById("open");
let flag = true;
svg1.addEventListener('click', function() {
if (flag == true) {
close.beginElement();
flag = false;
} else {
open.beginElement();
flag = true;
}
});
<div class="heart-container">
<svg id="svg1" width="40" height="40" viewBox="0 0 40 40" class='heart-stroke'>
<defs>
<filter id="red_fill" x="0%" y="0%">
<feFlood flood-color="#ded9d5" />
<feOffset dx="0">
<!-- Animation fills of color from top to bottom. -->
<animate id="close" attributeName="dy" values="0;40" dur="1s" begin="indefinite" repeatCount="3" restart="whenNotActive" fill="freeze"/>
<!-- Animation fills of color from bottom to top. -->
<animate id="open" attributeName="dy" values="40;0" dur="1s" begin="indefinite" repeatCount="3" restart="whenNotActive" fill="freeze"/>
</feOffset>
<feComposite operator="in" in2="SourceGraphic" />
<feComposite operator="over" in2="SourceGraphic" />
</filter>
</defs>
<path filter="url(#red_fill)" stroke="red" stroke-width="2" fill="red" d="M20,35.07,4.55,19.62a8.5,8.5,0,0,1-.12-12l.12-.12a8.72,8.72,0,0,1,12.14,0L20,10.77l3.3-3.3A8.09,8.09,0,0,1,29.13,4.9a8.89,8.89,0,0,1,6.31,2.58,8.5,8.5,0,0,1,.12,12l-.12.12Z"/>
</svg>
<a href='#' class='heart-clip'></a>
</div>
I have this animated graph that I created, but the start of the path, for some reason, was at 90deg, so I put a transform: rotate(-90deg) on it to start from 0deg. This works fine on my desktop in Chrome and Safari, but when I view it on my iPhone, it seems to ignore my rotate and go back to its default 90deg starting point. I've tried a bunch of prefixes and nothing changes.
Here's the link on CodePen
body {
background-color: #34495e;
}
.skills-graph {
fill: transparent;
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
margin: auto;
}
#javascript {
visibility: visible;
stroke: #ecf0f1;
animation-name: javascript;
animation-duration: 1s;
animation-timing-function: ease;
animation-delay: 0s;
animation-iteration-count: 1;
animation-direction: normal;
stroke-dasharray: 880;
stroke-dashoffset: 780;
animation-fill-mode: forwards;
}
#keyframes javascript {
0% {
stroke-dashoffset: 880;
stroke: white;
}
50% {
stroke: #ecf0f1;
}
100% {
stroke-dashoffset: 780;
stroke: #ecf0f1;
}
}
#html {
visibility: visible;
fill: transparent;
stroke: #95a5a6;
animation-name: html;
animation-duration: 1s;
animation-timing-function: ease;
animation-delay: 0s;
animation-iteration-count: 1;
animation-direction: normal;
stroke-dasharray: 691;
stroke-dashoffset: 271;
animation-fill-mode: forwards;
}
#keyframes html {
0% {
stroke-dashoffset: 691;
stroke: white;
}
50% {
stroke: #95a5a6;
}
100% {
stroke-dashoffset: 271;
stroke: #95a5a6;
}
}
#css {
visibility: visible;
fill: transparent;
stroke: #3dd0ac;
animation-name: css;
animation-duration: 1s;
animation-timing-function: ease;
animation-delay: 0s;
animation-iteration-count: 1;
animation-direction: normal;
stroke-dasharray: 502;
stroke-dashoffset: 172;
animation-fill-mode: forwards;
}
#keyframes css {
0% {
stroke-dashoffset: 502;
stroke: white;
}
50% {
stroke: #3dd0ac;
}
100% {
stroke-dashoffset: 172;
stroke: #3dd0ac;
}
}
<div id="skills-graph">
<!-- JavaScript Graph -->
<svg id="javascript" class="skills-graph" width="300" height="300">
<circle cx="150" cy="150" r="140" stroke-width="20"/>
</svg>
<!-- HTML Graph -->
<svg id="html" class="skills-graph" width="300" height="300">
<circle cx="150" cy="150" r="110" stroke-width="20"/>
</svg>
<!-- CSS Graph -->
<svg id="css" class="skills-graph" width="300" height="300">
<circle cx="150" cy="150" r="80" stroke-width="20"/>
</svg>
</div>
I do not have the answer, but i played a little bit with the codepen snippet on my iPhone 6s (safari) and when i changed the "-webkit-transform: rotate(-90deg);" (in .skills-graph) to "-webkit-transform: rotate(170deg);" it changes direction. Maybe you can find out the answer now yourself. (i'm not that good with code). Good luck!
EDIT: with "-webkit-transform: rotate(-89deg);" it seems right.
I've got a strange bug I can't seem to figure out:
I want to combine two CSS animation properties (opacity & transform: translate), and my target is an inline SVG element.
The combo is perfect in Chrome, fidgety in Firefox, and doesn't work in Safari.
Safari seems only capable of doing one or the other, not both at the same time. No idea what happens in IE at the moment as I'm on a Mac.
See example: http://jsfiddle.net/712xwmss/
If anyone can help get it working smoothly across all 4 browsers it'd be greatly appreciated.
SVG:
<svg width="28" height="65" viewBox="0 0 28 65" xmlns="http://www.w3.org/2000/svg" class="center-block svgscroll">
<title>Example</title>
<g fill="none" fill-rule="evenodd">
<path d="M5 44.7l7 6.953 7-6.953" class="svgarrow sa1" stroke="red" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
<path d="M3 50.66l9 8.94 9-8.94" class="svgarrow sa2" stroke="blue" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
</g>
CSS:
.svgarrow {
-moz-animation: drop 1s infinite;
-webkit-animation: drop 1s infinite;
animation: drop 1s infinite;
}
.svgarrow.sa1 {
-moz-animation-delay: 0.2s;
-webkit-animation-delay: 0.2s;
animation-delay: 0.2s;
}
.svgarrow.sa2 {
-moz-animation-delay: 0.1s;
-webkit-animation-delay: 0.1s;
animation-delay: 0.1s;
}
#-moz-keyframes drop {
0% {
-moz-transform: translateY(0px);
transform: translateY(0px);
opacity: 0;
}
100% {
-moz-transform: translateY(4px);
transform: translateY(4px);
opacity: 1;
}
}
#-webkit-keyframes drop {
0% {
-webkit-transform: translateY(0px);
transform: translateY(0px);
opacity: 0;
}
100% {
-webkit-transform: translateY(4px);
transform: translateY(4px);
opacity: 1;
}
}
#keyframes drop {
0% {
-moz-transform: translateY(0px);
-ms-transform: translateY(0px);
-webkit-transform: translateY(0px);
transform: translateY(0px);
opacity: 0;
}
100% {
-moz-transform: translateY(4px);
-ms-transform: translateY(4px);
-webkit-transform: translateY(4px);
transform: translateY(4px);
opacity: 1;
}
}
You should update Safari, It is fixed on latest version.
Latest Safari version for Mac
Safari 5.1.7 (Windows)
I have svg file, which i need to animate, i didn know how to animate polygon inside this file so i decide to use CSS3 animation intead, but not all browser display it right, i mean for firefox and safari there is no animation, why?
This is svg file code: (plus_animation.svg)
<?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" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="104.5px"
height="104px" viewBox="0 0 104.5 104" enable-background="new 0 0 104.5 104" xml:space="preserve">
<style type="text/css" >
<![CDATA[
#-webkit-keyframes pulse_animationW {
0% { -webkit-transform: scale(1); }
20% { -webkit-transform: scale(0.9); }
40% { -webkit-transform: scale(0.7); }
50% { -webkit-transform: scale(0.5); }
60% { -webkit-transform: scale(0.7); }
80% { -webkit-transform: scale(0.9); }
100% { -webkit-transform: scale(1); }
}
#-moz-keyframes pulse_animationM {
0% { -moz-transform: scale(1); }
20% { -moz-transform: scale(0.9); }
40% { -moz-transform: scale(0.7); }
50% { -moz-transform: scale(0.5); }
60% { -moz-transform: scale(0.7); }
80% { -moz-transform: scale(0.9); }
100% { -moz-transform: scale(1); }
}
#-moz-keyframes pulse_animationMS {
0% { -ms-transform: scale(1); }
20% { -ms-transform: scale(0.9); }
40% { -ms-transform: scale(0.7); }
50% { -ms-transform: scale(0.5); }
60% { -ms-transform: scale(0.7); }
80% { -ms-transform: scale(0.9); }
100% { -ms-transform: scale(1); }
}
#keyframes pulse_animation {
0% { transform: scale(1); }
20% { transform: scale(0.9); }
40% { transform: scale(0.7); }
50% { transform: scale(0.5); }
60% { transform: scale(0.7); }
80% { transform: scale(0.9); }
100% { transform: scale(1); }
}
#topPlus{
-webkit-animation-name: 'pulse_animationW';
-webkit-animation-duration: 1000ms;
-webkit-transform-origin:50% 50%;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: 'pulse_animationM';
-moz-animation-duration: 1000ms;
-moz-transform-origin:50% 50%;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: 'pulse_animationMS';
-ms-animation-duration: 1000ms;
-ms-transform-origin:50% 50%;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
animation-name: 'pulse_animation';
animation-duration: 1000ms;
transform-origin:50% 50%;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
.botPlus{
-webkit-animation-name: 'pulse_animationW';
-webkit-animation-duration: 500ms;
-webkit-transform-origin:50% 50%;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: 'pulse_animationM';
-moz-animation-duration: 500ms;
-moz-transform-origin:50% 50%;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: 'pulse_animationMS';
-ms-animation-duration: 500ms;
-ms-transform-origin:50% 50%;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
animation-name: 'pulse_animation';
animation-duration: 500ms;
transform-origin:50% 50%;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
#midPlus{
-webkit-animation-name: 'pulse_animationW';
-webkit-animation-duration: 2000ms;
-webkit-transform-origin:50% 50%;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: 'pulse_animationM';
-moz-animation-duration:2000ms;
-moz-transform-origin:50% 50%;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: 'pulse_animationMS';
-ms-animation-duration: 2000ms;
-ms-transform-origin:50% 50%;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
animation-name: 'pulse_animation';
animation-duration: 2000ms;
transform-origin:50% 50%;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
]]>
</style>
<g id="Warstwa_2" display="none">
<rect x="-2637.5" y="-1982" display="inline" fill="#1D1D1B" stroke="#1D1D1B" stroke-miterlimit="10" width="6919" height="3576"/>
</g>
<g id="Warstwa_1">
<g>
<polygon id="midPlus" fill="#FFFFFF" points="56,48.5 56,2.5 49,2.5 49,48.5 3,48.5 3,55.5 49,55.5 49,101.5 56,101.5 56,55.5 102,55.5
102,48.5 "/>
<rect class="botPlus" x="3.086" y="82.952" fill="#FFFFFF" width="32.817" height="3.834"/>
<rect class="botPlus" x="17.578" y="68.462" fill="#FFFFFF" width="3.834" height="32.815"/>
<polygon id="topPlus" fill="#FFFFFF" points="102,17.5 87,17.5 87,2.5 83,2.5 83,17.5 69,17.5 69,21.5 83,21.5 83,35.5 87,35.5 87,21.5
102,21.5"/>
<rect x="3.332" y="3.06" fill="none" stroke="#FFFFFF" stroke-width="0.996" stroke-miterlimit="10" width="97.971" height="97.973"/>
<rect x="3.332" y="3.06" fill="none" stroke="#FFFFFF" stroke-width="0.996" stroke-miterlimit="10" width="97.971" height="97.973"/>
<rect x="19.495" y="19.223" fill="none" stroke="#FFFFFF" stroke-width="0.996" stroke-miterlimit="10" width="65.646" height="65.646"/>
<rect x="2.833" y="2.561" fill="none" width="98.968" height="98.97"/>
</g>
</g>
</svg>
This is code in html page:
<div class="col-sm-offset-1 col-sm-2 text-center logoSVG">
<img src="~/Content/img/technology_partners/benefits/plus.svg" alt="SVG">
<p class="benefit-description">#Model.Benefit_1Text</p>
</div>
this is jQuery code:
$(document).ready(function () {
$('#benefits-div .logoSVG img').hover(function () {
var split = $(this).attr("src").split(".svg");
$(this).attr("src", split[0] + "_animation.svg");
}, function () {
var split = $(this).attr("src").split("_animation.svg");
$(this).attr("src", split[0] + ".svg");
});
});
Hey i'm trying to make a fancy border animation around some words and it's working well in Firefox & Chrome but not in IE. I was wondering if somebody knew why it isnt working in IE? The animation won't initiate.
My HTML
<div class="box">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
<line class="top" x1="-146" y2="0" x2="400" y2="0" />
<line class="left" x1="0" y1="60" x2="0" y2="-30" />
<line class="bottom" x1="292" y1="30" x2="-264" y2="30" />
<line class="right" x1="146" y1="-30" x2="146" y2="60" />
</svg>
<h2>My Words</h2>
My CSS
h2 {
font-family:'Source Sans Pro', sans-serif;
font-size: 1em;
text-align: center;
line-height: 30px;
color: black;
letter-spacing: 0.07em;
}
.box {
width: 146px;
height: 30px;
position: relative;
margin: 0 auto 15px auto;
color: #2c3e50;
padding-bottom: 0.05em;
padding-left: 1px;
padding-right: 0.05em;
}
.box svg {
position: absolute;
top: 0;
left: 0;
overflow:hidden;
}
.box svg line {
stroke-width: 3;
stroke: #000;
fill: none;
}
.box svg line.top, .box svg line.bottom, .box svg line.left, .box svg line.right {
-webkit-animation-delay: 0.25s !important;
-moz-animation-delay: 0.25s !important;
-ms-animation-delay: 0.25s !important;
-o-animation-delay: 0.25s !important;
animation-delay: 0.25s !important;
}
.box svg line.top {
stroke-dasharray: 146;
-webkit-animation: Topline 1s;
-moz-animation: Topline 1s;
-ms-animation: Topline 1s;
-o-animation: Topline 1s;
animation: Topline 1s;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
-o-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.box svg line.bottom {
stroke-dasharray: 146;
-webkit-animation: Bottomline 1s;
-moz-animation: Bottomline 1s;
-ms-animation: Bottomline 1s;
-o-animation: Bottomline 1s;
animation: Bottomline 1s;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
-o-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.box svg line.left {
stroke-dasharray: 30;
-webkit-animation: Leftline 1s;
-moz-animation: Leftline 1s;
-ms-animation: Leftline 1s;
-o-animation: Leftline 1s;
animation: Leftline 1s;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
-o-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.box svg line.right {
stroke-dasharray: 30;
-webkit-animation: Rightline 1s;
-moz-animation: Rightline 1s;
-ms-animation: Rightline 1s;
-o-animation: Rightline 1s;
animation: Rightline 1s;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
-o-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
#-webkit-keyframes Topline {
100% {
-webkit-transform: translateX(-146px);
}
}
#keyframes Topline {
100% {
-moz-transform: translateX(-146px);
-ms-transform: translateX(-146px);
-o-transform: translateX(-146px);
transform: translateX(-146px);
}
}
#-webkit-keyframes Bottomline {
100% {
-webkit-transform: translateX(146px);
}
}
#keyframes Bottomline {
100% {
-moz-transform: translateX(146px);
-ms-transform: translateX(146px);
-o-transform: translateX(146px);
transform: translateX(146px);
}
}
#-webkit-keyframes Leftline {
100% {
-webkit-transform: translateY(30px);
}
}
#keyframes Leftline {
100% {
-moz-transform: translateY(30px);
-ms-transform: translateY(30px);
-o-transform: translateY(30px);
transform: translateY(30px);
}
}
#-webkit-keyframes Rightline {
100% {
-webkit-transform: translateY(-30px);
}
}
#keyframes Rightline {
100% {
-moz-transform: translateY(-30px);
-ms-transform: translateY(-30px);
-o-transform: translateY(-30px);
transform: translateY(-30px);
}
}
Here is a setup of what i'm trying to accomplish : Fiddle
And this is the demo that I roughly followed.