Resize HTML5 canvas to fit window

前端 未结 16 1448
遥遥无期
遥遥无期 2020-11-22 12:03

How can I automatically scale the HTML5 element to fit the page?

For example, I can get a

to scale by setting th
16条回答
  •  醉梦人生
    2020-11-22 12:22

    Basically what you have to do is to bind the onresize event to your body, once you catch the event you just need to resize the canvas using window.innerWidth and window.innerHeight.

    
    
    
    
        Canvas Resize
    
        
    
    
    
            Your browser doesn't support canvas
    
    
    

提交回复
热议问题