HTML5 Game - Drawing canvas after dom loaded

Description

Drawing canvas after dom loaded

Demo

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<title>BasicExample</title>
<script>
    function changeCanvasColor () {
        let canvas = document.getElementById("mycanvas");
        let context = canvas.getContext("2d");
        context.fillStyle = "blue";
        context.fillRect(0, 0, canvas.width, canvas.height);
    }/*  w  w w .j av  a  2 s  .com*/

    document.addEventListener('DOMContentLoaded', changeCanvasColor);
</script>
</head>
<body>
<div id="gameArea">
    <canvas id="mycanvas" width="800" height="480"></canvas>
</div>
</body>
</html>

Related Topic