Last active
January 1, 2016 23:09
-
-
Save sapslaj/8215085 to your computer and use it in GitHub Desktop.
Mini sprite viewer made with jQuery and some CSS tricks. Set variables in the URL, ie: spriteviewer.html?image=http://i.imgur.com/GAZG8wV.png&framesize=40&framecount=8&fps=30
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> | |
<html> | |
<body> | |
<div id="canvas"></div> | |
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script> | |
<script> | |
var options = {}; | |
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) { | |
options[key] = value; | |
}); | |
$(function() { | |
var canvas = $("#canvas"); | |
options['framesize'] = parseInt(options['framesize']); | |
options['framecount'] = parseInt(options['framecount']); | |
options['fps'] = parseInt(options['fps']); | |
canvas.width(options['framesize']); | |
canvas.height(options['framesize']); | |
canvas.css("background-image", "url(\"" + options['image'] + "\")"); | |
var i = options['framecount']; | |
setInterval(function () { | |
if (typeof options['reverse'] === 'undefined') { | |
i == 1 ? i = options['framecount'] : i--; | |
} else { | |
i == options['framecount'] ? i = 1 : i++; | |
} | |
canvas.css("background-position", ((options['framesize'] * i) + "px 0px")); | |
}, 1000 / options['fps']); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment