点击它时按钮就像按钮一样

时间:2016-02-29 07:25:30

标签: jquery css css3 twitter

我想要像Twitter的喜欢按钮这样的动画。我从Twitter截取了截图。这是来自它动画的一些图片:

1:

enter image description here

2:

enter image description here

3:

enter image description here

你知道有什么好的jQuery库或CSS3库可以使用这样的动画吗?

2 个答案:

答案 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');
});

检查小提琴:https://fiddle.jshell.net/0yyegtv9/

答案 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');
});