Skip to content

Instantly share code, notes, and snippets.

@LevShab
Created October 31, 2015 06:52
Show Gist options
  • Save LevShab/fc5727a7308c0bed2094 to your computer and use it in GitHub Desktop.
Save LevShab/fc5727a7308c0bed2094 to your computer and use it in GitHub Desktop.
GameJQ.html
<style>
.player{
width: 100px;
height: 100px;
background-color: #ff0000;
position: absolute;
}
.wall{
width: 100px;
height: 100px;
background-color: #0000FF;
position:relative;
top: 300px;
left: 300px;
}
</style>
<div class="player"></div>
<div class="wall"></div>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function()
{
$(document).keydown(function(e)
{
if(!$('.player').is(':animated'))
{
switch(e.keyCode)
{
case 37:
$('.player').css({"transform": "rotate(270deg)"}).animate({left: '-=15px'});
break;
case 38:
$('.player').css({"transform": "rotate(0deg)"}).animate({'marginTop': '-=15px'});
break;
case 39:
$('.player').css({"transform": "rotate(90deg)"}).animate({'marginLeft': '+=15px'});
break;
case 40:
$('.player').css({"transform": "rotate(180deg)"}).animate({'marginTop': '+=15px'});
break;
}
}
return false;
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment