Created
May 10, 2017 23:19
-
-
Save dursk/de7a59c5bad6c94dde67285b4aa630e6 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=de7a59c5bad6c94dde67285b4aa630e6
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
$("body").keydown(function(event) { | |
// STEP 1 | |
// Store the current left offset of the bar | |
// in the position variable below. | |
var position; | |
// STEP 2 | |
// For the left key, adjust the if statement so that | |
// it is only true if the position of the bar is greater than 13. | |
if (event.which === 37 && position > 13) { | |
$("#bar").css("left", position - 10); | |
// STEP 3 | |
// For the right key, adjust the if statement so that | |
// is is only true if the position of the bar is less than 483. | |
} else if (event.which === 39 && position < 483) { | |
$("#bar").css("left", position + 10); | |
} 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