Skip to content

Instantly share code, notes, and snippets.

@ihewro
Created June 1, 2018 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihewro/90f7e7cee70bacc9351e51ac9f4c8b22 to your computer and use it in GitHub Desktop.
Save ihewro/90f7e7cee70bacc9351e51ac9f4c8b22 to your computer and use it in GitHub Desktop.
一个点赞的效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<style>
.heart {
background-image: url(https://cinwell.com/_nuxt/img/heart.3c55287.png);
background-position: 0;
background-repeat: no-repeat;
background-size: 2900%;
height: 50px;
width: 50px;
margin: auto;
}
.heart:hover {
background-position: 3.57142857%
}
.heart.animate{
-webkit-animation: fave-heart 1s steps(28);
animation: fave-heart 1s steps(28);
background-position: 100%
}
.heart.loved {
background-position: 100%
}
@-webkit-keyframes fave-heart {
0% {
background-position: 0 0
}
to {
background-position: 100%
}
}
@keyframes fave-heart {
0% {
background-position: 0 0
}
to {
background-position: 100%
}
}
</style>
</head>
<body>
<div class="heart"></div>
<script>
$(".heart").click(function(){
if ($(".heart").hasClass("animate")){
$(".heart").removeClass("animate");
}else{
$(".heart").addClass("animate");
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment