Like Icon colour on click - html

I've created a "like" feature with an icon that will be added in product card.
I need to make the icon stay red once it's been clicked, but it also needs to display the animation at the same time.
By the looks of it they're overlapping each other and ones cancelling the other out.
.heart{
font-size: 24px!important;
color: #fff;
}
/* PUSH HOVER EFFECT */
#-webkit-keyframes hvr-push {
50% {
-webkit-transform: scale(0.8);
transform: scale(0.8);
}
100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
#keyframes hvr-push {
50% {
-webkit-transform: scale(0.8);
transform: scale(0.8);
}
100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
.hvr-push {
display: inline-block;
vertical-align: middle;
-webkit-transform: perspective(1px) translateZ(0);
transform: perspective(1px) translateZ(0);
box-shadow: 0 0 1px transparent;
}
.hvr-push:active {
-webkit-animation-name: hvr-push;
animation-name: hvr-push;
-webkit-animation-duration: 0.3s;
animation-duration: 0.3s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-animation-iteration-count: 1;
animation-iteration-count: 1;
}
/* CHANGE ICON ON HOVER */
.change-icon > .fa + .fa,
.change-icon:hover > .fa {
display: none;
}
.change-icon:hover > .fa + .fa {
display: inherit;
color:red;
}
<div>
<span class="change-icon">
<i class="hvr-push heart fa fa-heart-o"></i>
<i class="hvr-push heart fa fa-heart"></i>
</span>
</div>

Try this:
/* when a user clicks, toggle the 'is-animating' class */
$(".heart").on('click touchstart', function(){
$(this).toggleClass('is_animating');
$(this).toggleClass('liked');
});
/*when the animation is over, remove the class*/
$(".heart").on('animationend', function(){
$(this).toggleClass('is_animating');
});
.heart {
cursor: pointer;
height: 50px;
width: 50px;
background-image:url( 'https://abs.twimg.com/a/1446542199/img/t1/web_heart_animation.png');
background-position: left;
background-repeat:no-repeat;
background-size:2900%;
}
.heart:hover {
background-position:right;
}
.liked {
background-position:right;
}
.is_animating {
animation: heart-burst .8s steps(28) 1;
}
#keyframes heart-burst {
from {background-position:left;}
to { background-position:right;}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="heart"></div>

Related

CSS3 animation - two issues

Here are some issues which I can't seem to figure out.
When you hover on the image I am animating a few styles but as you will see, when the border size increases, everything else moves with it.
When you change the sidetext to something longer or shorter, it decides to move positions.
Please can someone explain what I am doing wrong?
/*
Colors:
#FF0F00 = red
#FFFF04 = yellow
#387F23 = green
*/
* {
box-sizing: border-box;
}
body {
margin: 0;
background-color: yellow;
font-family: Arial, Helvetica, sans-serif;
}
.animate {
animation-fill-mode: forwards;
animation-duration: 1s;
}
.one {
-webkit-animation-delay: 0.4s;
-moz-animation-delay: 0.4s;
animation-delay: 0.4s;
}
.two {
-webkit-animation-delay: 1.7s;
-moz-animation-delay: 1.7s;
animation-delay: 1.7s;
}
.three {
-webkit-animation-delay: 2.3s;
-moz-animation-delay: 2.3s;
animation-delay: 2.3s;
}
.four {
-webkit-animation-delay: 3.3s;
-moz-animation-delay: 3.3s;
animation-delay: 3.3s;
}
#keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.fadeIn {
-webkit-animation-name: fadeIn;
animation-name: fadeIn;
}
#keyframes fadeInDown {
from {
opacity: 0;
-webkit-transform: translate3d(0, -100%, 0);
transform: translate3d(0, -100%, 0);
}
to {
opacity: 1;
-webkit-transform: none;
transform: none;
}
}
.fadeInDown {
-webkit-animation-name: fadeInDown;
animation-name: fadeInDown;
}
#keyframes fadeInLeft {
from {
opacity: 0;
-webkit-transform: translate3d(-100%, 0, 0);
transform: translate3d(-100%, 0, 0);
}
to {
opacity: 1;
-webkit-transform: none;
transform: none;
}
}
.fadeInLeft {
-webkit-animation-name: fadeInLeft;
animation-name: fadeInLeft;
}
/* FADE IN RIGHT */
#-webkit-keyframes fadeInRight {
from {
opacity: 0;
-webkit-transform: translate3d(100%, 0, 0);
transform: translate3d(100%, 0, 0);
}
to {
opacity: 1;
-webkit-transform: none;
transform: none;
}
}
#keyframes fadeInRight {
from {
opacity: 0;
-webkit-transform: translate3d(100%, 0, 0);
transform: translate3d(100%, 0, 0);
}
to {
opacity: 1;
-webkit-transform: none;
transform: none;
}
}
.fadeInRight {
-webkit-animation-name: fadeInRight;
animation-name: fadeInRight;
}
.container {
margin-left: auto;
margin-right: auto;
width: 100%;
}
.hero__img img {
max-width: 100%;
vertical-align: middle;
}
.hero__center:after {
position: absolute;
content: " ";
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: red;
/* z-index: -1; */
opacity: 0;
transition: opacity 0.4s ease-in;
}
#media (min-width: 920px) {
.hero {
margin: 0 auto;
width: 700px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
opacity: 0;
}
.hero__heading {
position: absolute;
font-size: 80px;
color: #0004f3;
text-transform: uppercase;
font-weight: bold;
font-kerning: -3px;
letter-spacing: 4px;
z-index: 1;
}
.hero__heading--top {
left: -85px;
top: -150px;
opacity: 1;
}
.hero__heading--bottom {
right: -85px;
bottom: -150px;
opacity: 1;
}
.hero__center {
position: relative;
border: 5px solid blue;
transition: border 0.4s ease-in;
}
.hero__center:hover {
border: 10px solid #387F23;
transition: border 0.4s ease-in;
}
.hero__center:hover:after {
opacity: 0.4;
transition: opacity 0.4s ease-in;
}
.hero__center:hover .hero__sideText {
color: red;
transition: color 0.4s ease-in;
}
.hero__img img {
opacity: 1;
transition: opacity 0.4s ease-in;
}
/* .hero__img:hover img {
opacity: 0.4;
transition: opacity 0.4s ease-in;
} */
/* .hero__center:hover {
border: 5px solid green;
transition: border 0.5s;
} */
.hero__sideText {
position: absolute;
top: 50%;
color: #0004f3;
transition: color 0.4s ease-in;
}
.hero__side--left {
left: -50px;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
transform-origin: center center;
}
.hero__side--right {
right: -50px;
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-ms-transform: rotate(270deg);
-o-transform: rotate(270deg);
transform: rotate(270deg);
transform-origin: center center;
}
}
<div class="container">
<div class="hero animate fadeIn one">
<div class="hero__center">
<span class="hero__heading hero__heading--top animate fadeInLeft one">Lorem</span>
<span class="hero__heading hero__heading--bottom animate fadeInRight one">Ipsum</span>
<div class="hero__img">
<img src="http://via.placeholder.com/980x550" alt="">
</div>
<span class="hero__sideText hero__side--left">Side text</span>
<span class="hero__sideText hero__side--right">Side text</span>
</div>
</div>
</div>
Since the size of your box changes by changing the border width, the elements change their position aswell.
try adding :
.hero__center:hover {
margin:-5px;
}
to work against the border change.
2.
The transform rotation uses the center point of your element as its origin (transform-origin: center center;). When increasing the characters you increase the width so the point which the rotation choses as its origin shifts aswell.
To change that you have to fix that point to a specific location. Try adding a div wrappers around your sideText spans with the following css:
.wrapper-left {
position:relative;
left: -50%;
}
.wrapper-right {
position:relative;
left: 50%;
}

CSS rotated object doesn't rotate until after animation is complete

I'm creating a simple checkbox override in CSS and am trying to add an animation to make it appear. Because the checkmark is just a rotated rectangle with borders on the bottom and side, when I animate it, it isn't actually rotated until after the animation is complete. I tried adding the transform:rotate() to the animation keyframes, but for some reason when I do that, it doesn't animate at all. How can I ensure that the checkmark remains rotated 45ยบ throughout the animation process, and after it completes?
Demo: https://jsfiddle.net/brandonscript/L09h7jng/
HTML
<h3>Checkboxes</h3>
<div>
<input id="checkbox-1" class="checkbox" name="checkbox-1" type="checkbox" checked>
<label for="checkbox-1" class="checkbox-label">First Choice</label>
</div>
(S)CSS
$color-success: #12C376;
#-webkit-keyframes bounce {
0% {
-webkit-transform: scale(.25);
opacity: .8;
}
50% {
-webkit-transform: scale(1.4);
opacity: .25;
}
100% {
-webkit-transform: scale(1);
opacity: .8;
}
}
#keyframes bounce {
0% {
transform: scale(.25);
opacity: .8;
}
50% {
transform: scale(1.4);
opacity: 1.4;
}
100% {
transform: scale(1);
opacity: 1;
}
}
.checkbox {
position: absolute;
display: none;
}
.checkbox + label {
position: relative;
display: block;
padding-left: 30px;
cursor: pointer;
vertical-align: middle;
}
.checkbox + label:hover:before {
animation-duration: 0.4s;
animation-fill-mode: both;
animation-name: hover-color;
}
.checkbox + label:before {
position: absolute;
top: 0;
left: 0;
display: inline-block;
width: 20px;
height: 20px;
content: '';
border: 1px solid $color-piston;
}
.checkbox + label:after {
position: absolute;
display: none;
content: '';
}
.checkbox:checked + label:before {
//animation-name: none;
}
.checkbox:checked + label:after {
display: block;
}
.checkbox + label:before {
border-radius: 3px;
}
.checkbox + label:after {
top: 2px;
left: 7px;
box-sizing: border-box;
width: 6px;
height: 12px;
border-width: 2px;
border-style: solid;
border-color: $color-success;
border-top: 0;
border-left: 0;
transition: all .2s;
-webkit-animation: bounce 0.3s;
-webkit-animation-iteration-count: 1;
-webkit-animation-fill-mode: forward;
-moz-animation: bounce 0.3s;
-moz-animation-iteration-count: 1;
-moz-animation-fill-mode: forward;
animation: bounce 0.3s;
animation-iteration-count: 1;
animation-fill-mode: forward;
transform: rotate(45deg);
}
.checkbox:checked + label:before {
border: 1px solid $color-piston;
background: #FFFFFF;
}
Put your rotation inside your keyframe (do this for both webkit and normal):
#keyframes bounce {
0% {
transform: scale(.25) rotate(15deg);
opacity: .8;
}
50% {
transform: scale(1.4);
opacity: 1.4;
}
100% {
transform: scale(1) rotate(45deg);
opacity: 1;
}
}
The :after should also have the rotate applied:
.checkbox + label:after {
...
transform: rotate(45deg);
}
fiddle: https://jsfiddle.net/L09h7jng/4/
try to put rotate(45deg) to each line of all transform in animation progress...
#-webkit-keyframes bounce {
0% {
-webkit-transform: scale(.25) rotate(45deg);
opacity: .8;
}
50% {
-webkit-transform: scale(1.4) rotate(45deg);
opacity: 1.4;
}
100% {
-webkit-transform: scale(1) rotate(45deg);
opacity: 1;
}
}
#keyframes bounce {
0% {
transform: scale(.25) rotate(45deg);
opacity: .8;
}
50% {
transform: scale(1.4) rotate(45deg);
opacity: 1.4;
}
100% {
transform: scale(1) rotate(45deg);
opacity: 1;
}
}

Why is the spinner not spinning/rotating?

I have created a anchor link button where I want to show Spinner animation when I click on button in :focus state. I'm using Font Awesome to show animation but when I click on the button, the spinner animation is not working.
Note: I don't want to use JavaScript here just want to do with Pure
CSS
Here is the CodePen link https://codepen.io/rhulkashyap/pen/vLPNdQ
#import url(https://fonts.googleapis.com/css?family=Titillium+Web);
body {
font-family: 'Titillium Web', sans-serif;
text-align: center;
}
#button {
padding: 15px;
background-color: green;
color: #fff;
text-decoration: none;
border-radius: 5px;
width: 300px;
display: inline-block;
text-align: center;
font-size: 25px;
-webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
#button:before {
content: "\f090";
font-family: FontAwesome;
margin-right: 5px;
}
#button:focus {
background-color: #02b402;
}
#button:focus:before {
content: "\f1ce";
-webkit-animation: spin .8s ease infinite;
animation: spin .8s ease infinite;
}
#-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
#keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<h2> Click Here</h2>
<a id="button" href="javascript:void(0)">Enter In</a>
Transforms are supposed to work only on block level elements (including inline-block). Making the pseudo-element as display:inline-block makes the animation work.
After commenting on the question, I did see that the animation wasn't working in Chrome v50 (dev-m) also while it was working in Chrome v43. So, the current behavior seems to be consistent
#import url(https://fonts.googleapis.com/css?family=Titillium+Web);
body {
font-family: 'Titillium Web', sans-serif;
text-align: center;
}
#button {
padding: 15px;
background-color: green;
color: #fff;
text-decoration: none;
border-radius: 5px;
width: 300px;
display: inline-block;
text-align: center;
font-size: 25px;
-webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
#button:before {
display: inline-block;
content: "\f090";
font-family: FontAwesome;
margin-right: 5px;
}
#button:focus {
background-color: #02b402;
}
#button:focus:before {
content: "\f1ce";
-webkit-animation: spin .8s ease infinite;
animation: spin .8s ease infinite;
}
#-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
#keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<h2> Click Here</h2>
<a id="button" href="javascript:void(0)">Enter In</a>

CSS Animation not working properly in wow js

I have integrated the wow.js for my project and i have encountered a problem with animation.
The animation class which i used to animate the div is working only if i paste the css class from animate.css into my page as embedded style sheet and also the div is showing even if i give a delay in data-wow-delay="5s"and animation works properly after 5 sec. Plz help me if anyone knows why this is happening.
Here is my code..
HTML :
<div class="cssAnimation hidediv">
<div class="dial1 wow slideInLeft " data-wow-duration="2s" data-wow-delay="5s">
Anmation goes here 1
</div>
</div>
CSS :
<style type="text/css">
.dial1{
width:200px;
height: 100px;
display: block;
position: absolute;
background: #000;
color:#fff;
padding: 10px;
right: 0;
z-index: 9999;
}
.dial2{
width:200px;
height: 100px;
display: block;
position: absolute;
background: #000;
color:#fff;
padding: 10px;
right: 210px;
}
.hidediv{
-webkit-animation: hide 2s forwards;
-webkit-animation-iteration-count: 1;
-webkit-animation-delay: 5s;
animation: hide 2s forwards;
animation-iteration-count: 1;
animation-delay: 5s;
}
#-webkit-keyframes hide {
0% {
opacity: 1;
}
100% {
opacity: 0;
visibility:hidden;
display: none;
}
}
#keyframes hide {
0% {
opacity: 1;
}
100% {
opacity: 0;
visibility:hidden;
display: none;
}
}
.cssAnimation{
width:600px;
height: 300px;
position: absolute;
/* display: none; */
z-index: 9999;
}
#-webkit-keyframes slideInLeft {
0% {
opacity: 0;
-webkit-transform: translateX(-2000px);
transform: translateX(-2000px);
}
100% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
}
#keyframes slideInLeft {
0% {
opacity: 0;
-webkit-transform: translateX(-2000px);
-ms-transform: translateX(-2000px);
transform: translateX(-2000px);
}
100% {
-webkit-transform: translateX(0);
-ms-transform: translateX(0);
transform: translateX(0);
}
}
.slideInLeft {
-webkit-animation-name: slideInLeft;
animation-name: slideInLeft;
}
</style>
Your css needs to include the .animated class from animate.css, as that's what will be added by Wow.js (unless you specify another selector) when the element is in view, triggering your animations.

Text flickers during animation on firefox

I want to do slide animation using CSS and Angular Js. I am upto this :JSFiddle
On chrome this animation works flawless. But on Firefox text shakes and flickers little bit when animation goes on.I am not able to figure out exact issue . Any idea ..
Code :
HTML:
<div ng-controller="animationCtrl">
<ul class='list'>
<li>
<div class="slide-animation">
<div class="slide-animation-wrap new-slide-wrap {{cssTimeInfo1}}"> <span class="text">{{valueSet1[0]}}</span>
<label class="small-label">{{valueSet2[1]}}</label>
</div>
<div class="slide-animation-wrap old-slide-wrap {{cssTimeInfo1}}"> <span class="text">{{valueSet1[1]}}</span>
<label class="small-label">{{valueSet2[1]}}</label>
</div>
</div>
</li>
</ul>
</div>
CSS :
.list > li {
box-sizing:border-box;
height: 72px;
display: inline-block;
margin-right: 1.06%;
padding: 15px;
vertical-align: top;
background-color: #f1f1f1;
-webkit-box-shadow: 0 0 7px rgba(210, 210, 210, 0.3) inset;
box-shadow: 0 0 7px rgba(210, 210, 210, 0.3) inset;
}
.small-label {
height: 24px;
display: block;
font-size: 0.714em;
margin-bottom: 0;
color: #999999;
text-transform: uppercase;
text-align: center;
}
.text {
height: 24px;
display: block;
font-size: 1.286em;
margin-bottom: 3px;
color: #666666;
text-align: center;
}
/* Slide animation */
.slide-animation {
overflow: hidden;
position: relative;
height: 40px;
}
.slide-animation-wrap {
position: relative;
width: 100%;
}
.slide-animation-wrap.new-slide-wrap {
top: -45px;
}
.slide-animation-wrap.old-slide-wrap {
top: -51px;
}
.slide-animation-wrap.slide-in-animation,
.slide-animation-wrap.slide-out-animation {
-webkit-animation: slide-outside-animation 1s linear forwards;
-o-animation: slide-outside-animation 1s linear forwards;
animation: slide-outside-animation 1s linear forwards;
}
.slide-animation-wrap:before,
.slide-animation-wrap:after {
content: " ";
display: table;
}
.slide-animation-wrap:after {
clear: both;
}
.slide-animation-wrap:before,
.slide-animation-wrap:after {
content: " ";
display: table;
}
.slide-animation-wrap:after {
clear: both;
}
#-webkit-keyframes slide-outside-animation {
0% {
-webkit-transform: translateY(0px);
-ms-transform: translateY(0px);
transform: translateY(0px);
}
100% {
-webkit-transform: translateY(45px);
-ms-transform: translateY(45px);
transform: translateY(45px);
}
}
#-moz-keyframes slide-outside-animation {
0% {
-webkit-transform: translateY(0px);
-ms-transform: translateY(0px);
transform: translateY(0px);
}
100% {
-webkit-transform: translateY(45px);
-ms-transform: translateY(45px);
transform: translateY(45px);
}
}
#-ms-keyframes slide-outside-animation {
0% {
-webkit-transform: translateY(0px);
-ms-transform: translateY(0px);
transform: translateY(0px);
}
100% {
-webkit-transform: translateY(45px);
-ms-transform: translateY(45px);
transform: translateY(45px);
}
}
#keyframes slide-outside-animation {
0% {
-webkit-transform: translateY(0px);
-ms-transform: translateY(0px);
transform: translateY(0px);
}
100% {
-webkit-transform: translateY(45px);
-ms-transform: translateY(45px);
transform: translateY(45px);
}
}
Angular :
var myApp = angular.module('myApp',[]);
myApp.controller('animationCtrl', ['$scope','$interval', function ($scope,$interval) {
$scope.valueSet1=['HGFhgfsffghfhgf','HGFhgfsffghfhgf'];
$scope.valueSet2=['ABC','ABC'];
$scope.cssTimeInfo1 = "display-none";
$scope.cssTimeInfo2 = "display-none";
var flag=0;
$interval(function(){
//0
$scope.cssTimeInfo1='slide-in-animation';
$scope.cssTimeInfo2 = "display-none";
flag++;
if(flag>1){
flag=0;
//0
$scope.cssTimeInfo1 = " ";
$scope.cssTimeInfo2 = " ";
}
else{
//1
$scope.cssTimeInfo1 = "slide-out-animation";
$scope.cssTimeInfo2 = "slide-in-animation";
}
},1000);
}]);
I had a text flickering issue on Firefox with transforms. Adding
backface-visibility: hidden;
to the transformed element fixed the issue for me.
I fixed the issue by adding:
will-change: transform;
on the element being transformed.
Provides a rendering hint to the user agent, stating what kinds of changes the author expects to perform on the element.
(Firefox 36, Safari 9, Chrome 36, Opera 24)
See MDN reference (link) for more information.
Note (from the MDN reference): will-change is intended to be used as a last resort, in order to try to deal with existing performance problems. It should not be used to anticipate performance problems.