2017-12-21 42 views
0

제품 카드에 추가 될 아이콘과 함께 '좋아요'기능을 만들었습니다.클릭시 아이콘 색상이 비슷합니다

아이콘을 클릭하면 빨간색으로 유지해야하지만 동시에 애니메이션을 표시해야합니다.

외모에 의해 서로 겹치고 다른 것들은 취소됩니다.

.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>

+1

당신이 아이콘의 CSS를 포함 할 수 있습니다, 당신의 조각은 당신이 난에 대한 모든 CDN을 추가 할 수 –

+0

작동하지 않습니다 수업? –

+0

대신 codepen을 생성 할 수 있도록 모든 코드를 추가 할 수는 없지만 괜찮습니까? https://codepen.io/kellett/pen/dJXxYJ –

답변

1

이 시도 :

/* 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>

+0

안녕하세요 Darshit, 죄송합니다. 코딩이 최선이 아닙니다. 이전 코드를 제거해야합니까? 또한 내가 이것을 어디에 추가해야 하는가? –

+0

그냥 내 snippent 주어진 CSS와 HTML 및 jquery 당신을 대체하십시오. :) –

+0

고맙습니다 upvote 잊지 마세요 :) –