Skip to content

Instantly share code, notes, and snippets.

@hayashikun
Created March 21, 2016 07:59
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 hayashikun/a3473c70056d76bbd17a to your computer and use it in GitHub Desktop.
Save hayashikun/a3473c70056d76bbd17a to your computer and use it in GitHub Desktop.
<style>
#heart {
width: 280px;
height: 280px;
background-image: url(http://cdn-ak.f.st-hatena.com/images/fotolife/h/hayashikunsan/20160321/20160321164813.png);
background-position: left;
}
</style>
<div id="heart"></div>
<script>
document.getElementById("heart").addEventListener("click", function(el) {
var offset = 280 * 57;
var tm = setInterval(function() {
if (offset == 0) {
clearTimeout(tm)
} else {
el.target.style.backgroundPosition = offset + "px 50%";
}
offset -= 280;
}, 50);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment