问答详情
源自:-

Cannot set property 'onload' of null"

 Cannot set property 'onload' of null",是怎么回事?

提问者:樱沫 2016-09-18 11:01

个回答

  • Sonia_Sun
    2017-05-14 09:54:09

    js代码引用要在canvas标签下面

  • 樱沫
    2016-09-18 11:02:15

    document.body.onload = game;

    function game(){

    //初始工作

    init();

    }


    function init(){

    //获得canvas、context

    var can1 = document.getElementById("canvas1");//在前面:fishes、UI、dust、circle

    var ctx1 = can1.getContext();

    var can2 = document.getElementById("canvas2");//background、ane、fruits

    var ctx2 = can2.getContext();

    }


    function gameloop(){

    requestAnimFrame(gameloop);

    }