Skip to content

Instantly share code, notes, and snippets.

@kreas
Created April 17, 2012 14:18
Show Gist options
  • Save kreas/2406239 to your computer and use it in GitHub Desktop.
Save kreas/2406239 to your computer and use it in GitHub Desktop.
^_^
div.spawn{
background :yellow;
color: #000;
border: 1px solid #000;
width: 25px;
height: 25px;
text-align: center;
padding: 2px 0;
position: absolute;
}
<html>
<head>
</head>
<body>
</body>
</html>
spawn = "<div class='spawn'> ^_^ </div>";
sprite = 'div.spawn';
$(document).ready(function() {
$('body').append(spawn);
$(document).keydown(function(e) {
if (e.keyCode == 87) {
$(sprite).animate({
bottom: '+=25px'
}, 0);
} else if (e.keyCode == 83) {
$(sprite).animate({
bottom: '-=25px'
}, 0);
} else if (e.keyCode == 68) {
$(sprite).animate({
left: '+=25px'
}, 0);
} else if (e.keyCode == 65) {
$(sprite).animate({
left: '-=25px'
}, 0);
}
});
$(document).keyup(function(){
$(sprite).stop();
$(sprite).clearQueue();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment