addEventListener for keydown on Canvas

后端 未结 4 1842
忘了有多久
忘了有多久 2020-11-28 06:51

I am trying to make a canvas app that responds to keyboard and mouse input. I have this code:

canvas = document.getElementById(\'canvas\');
canvas.addEventLi         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 07:24

    encapsulate all of your js code within a window.onload function. I had a similar issue. Everything is loaded asynchronously in javascript so some parts load quicker than others, including your browser. Putting all of your code inside the onload function will ensure everything your code will need from the browser will be ready to use before attempting to execute.

提交回复
热议问题