Created
October 31, 2015 06:52
-
-
Save LevShab/fc5727a7308c0bed2094 to your computer and use it in GitHub Desktop.
GameJQ.html
This file contains hidden or 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
<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