html - How do I contain my JavaScript game in a div? -
in html, have section in have javascript adds event listener runs game:
<div class="content"> <script> window.addeventlistener('load', game.start); </script> </div> how make javascript contained within div above it? when shows, game outside of it.
i'm using crafty.js framework. documentation here: http://craftyjs.com/api/
as mentioned in 1 of comments, div id "cr-stage" important crafty.js. however, don't have include it. if leave out, automatically created.
<html> <head> <!-- crafty.js library, load server --> <script src="crafty.js"></script> <!-- script game's js goes --> <script src="mygame.js"></script> <script> window.addeventlistener('load', game.start); </script> </head> <body> </body> </html> if use above, cr-stage id created you.
another thing might relevant question if want center cr-stage , remove small gap automatically appears above it. that, use code:
<html> <head> <!-- crafty.js library, load server --> <script src="crafty.js"></script> <!-- script game's js goes --> <script src="mygame.js"></script> <script> window.addeventlistener('load', game.start); </script> <style type="text/css"> /* remove small gap @ top */ body { margin-top: 0 } /* horizontally center stage on page */ #cr-stage { margin: 0 auto 0 } </style> </head> <body> </body> </html>
Comments
Post a Comment