Created
May 9, 2017 00:21
-
-
Save dursk/7280140ba8c0b3ad124e699429717984 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=7280140ba8c0b3ad124e699429717984
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> | |
<head> | |
<title>Page Title</title> | |
</head> | |
<body> | |
<div id="game"> | |
<div id="bar"></div> | |
</div> | |
</body> | |
</html> |
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
{"enabledLibraries":["jquery"]} |
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
var position = $("#bar").offset().left; | |
$("body").keydown(function(event) { | |
if (event.which === 37 && position > 13) { | |
position = position - 10; | |
$("#bar").css("left", position); | |
} else if (event.which === 39 && position < 483) { | |
position = position + 10; | |
$("#bar").css("left", position); | |
} else { | |
return; | |
} | |
}); |
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
#game { | |
border: 5px solid black; | |
height: 500px; | |
width: 500px; | |
} | |
#bar { | |
background-color: black; | |
height: 8px; | |
width: 30px; | |
position: absolute; | |
margin-top: 480px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment