答案 0 :(得分:1)
HTML:
<div class="heart"></div>
CSS:
.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;
}
.animating {
animation: heart-burst .8s steps(28) 1;
}
@keyframes heart-burst {
from {background-position:left;}
to { background-position:righ;}
}
JAVASCRIPT:
$(".heart").on('click touchstart', function(){
$(this).toggleClass('animating');
});
$(".heart").on('animationend', function(){
$(this).toggleClass('animating');
});
答案 1 :(得分:0)
这是您正在寻找的东西: http://codepen.io/chrismabry/pen/ZbjZEj
/* when a user clicks, toggle the 'is-animating' class */
$(".heart").on('click touchstart', function(){
$(this).toggleClass('is_animating');
});
/*when the animation is over, remove the class*/
$(".heart").on('animationend', function(){
$(this).toggleClass('is_animating');
});