Skip to content

Instantly share code, notes, and snippets.

@KitaitiMakoto
Created May 18, 2016 23:32
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 KitaitiMakoto/089a70c0fe4a7530e30088a5e2e2adb1 to your computer and use it in GitHub Desktop.
Save KitaitiMakoto/089a70c0fe4a7530e30088a5e2e2adb1 to your computer and use it in GitHub Desktop.
<!doctype html>
<title>sprite</title>
<style>
div {
width: 64px;
height: 81px;
margin: 3em;
background-repeat: no-repeat;
background-image: url("senior-santa.png");
background-size: auto 100%;
}
</style>
<div></div>
<label>FPS<input name=fps type=number max=60 min=0 step=1 value=0></label>
<script>
(function() {
'use strict';
// 128 x 162 x 57
var div = document.querySelector('div');
var input = document.querySelector('input[name="fps"]');
var fps = Number(input.value);
input.addEventListener('change', event => {
fps = Number(event.target.value);
if (fps !== 0) {
step();
}
});
var current = 0;
var step = () => {
if (fps === 0) {
return;
}
div.style.backgroundPosition = -(33 + current) * 64 + 'px top';
current = (current + 1) % 24
setTimeout(step, 1000 / fps);
};
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment