实现收藏/取消收藏动效

heart_animation1.pngheart_animation2.png

<!-- 初始化未选中 -->
<span class="empty"></span>
<!-- 初始化已选中 -->
<!-- <span class="fill"></span> -->
<!-- 点击选中 -->
<!-- <span class="to-fill"></span> -->
<!-- 点击取消选中 -->
<!-- <span class="to-empty"></span> -->
$(".content").on("click","span",function(){
	if($(this).hasClass("empty")){
		$(this).removeClass("empty");
		$(this).addClass("to-fill");
	}
	else if($(this).hasClass("fill")){
		$(this).removeClass("fill");
		$(this).addClass("to-empty");
	}
	else if($(this).hasClass("to-fill")){
		$(this).removeClass("to-fill");
		$(this).addClass("to-empty");
	}
	else{
		$(this).removeClass("to-empty");
		$(this).addClass("to-fill");
	}
})
.product-detail .product-detail-right .tips span {
  cursor: pointer;
  /* width: 42px;
     height: 42px; */
  width: 0.64rem;
  height: 0.64rem;
  display: inline-block;
}
.product-detail .product-detail-right .tips span.empty {
  background: url(../images/heart_animation1.png) no-repeat;
  background-position: left;
  background-size: cover;
}
.product-detail .product-detail-right .tips span.fill {
  background: url(../images/heart_animation2.png) no-repeat;
  background-position: left;
  background-size: cover;
}
.product-detail .product-detail-right .tips span.to-fill {
  background: url(../images/heart_animation1.png) no-repeat;
  background-position: left;
  animation-name: toFill;
  animation-duration: 0.8s;
  animation-iteration-count: 1;
  animation-timing-function: steps(31);
  background-position: right;
  background-size: cover;
}
@keyframes toFill {
  0% {
    background-position: left;
  }
  100% {
    background-position: right;
  }
}
.product-detail .product-detail-right .tips span.to-empty {
  background: url(../images/heart_animation2.png) no-repeat;
  background-position: left;
  animation-name: toEmpty;
  animation-duration: 0.4s;
  animation-iteration-count: 1;
  animation-timing-function: steps(15);
  background-position: right;
  background-size: cover;
}
@keyframes toEmpty {
  0% {
    background-position: left;
  }
  100% {
    background-position: right;
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值