Resize HTML5 canvas to fit window

前端 未结 16 1151
遥遥无期
遥遥无期 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:13

    The following solution worked for me the best. Since I'm relatively new to coding, I like to have visual confirmation that something is working the way I expect it to. I found it at the following site: http://htmlcheats.com/html/resize-the-html5-canvas-dyamically/

    Here's the code:

    
    
    
        
        Resize HTML5 canvas dynamically | www.htmlcheats.com
        
    
    
    
        
        
    
        
     
    
    

    The blue border shows you the edge of the resizing canvas, and is always along the edge of the window, visible on all 4 sides, which was NOT the case for some of the other above answers. Hope it helps.

提交回复
热议问题