Created
May 18, 2016 23:32
-
-
Save KitaitiMakoto/089a70c0fe4a7530e30088a5e2e2adb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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