how to draw grid using html5 and (canvas or svg)

后端 未结 4 1802
北恋
北恋 2020-12-12 10:00

I want to draw a grid as shown in image but I totally don\'t have idea that where should I begin. Should I use SVG or should I use Canvas w

4条回答
  •  Happy的楠姐
    2020-12-12 10:35

    I am posting my code using canvas here on SO but I am also creating a working sample on JSFiddle here.

    
    
    
        StackOverflow test bed
        
    
    
        
    
    
    

    Using the canvas approach you can make the grid size dynamic by changing the separation parameter.

    However, if your grid size is going to be static I feel that maybe you don't need to draw the grid. Just for the sake of displaying a grid to the user you could use CSS to repeat a background image as demonstrated in the fiddle here. That will also be good on page performance.

提交回复
热议问题