1
Hello, what is the best way to make a grid for Javascript and HTML? I need that I can draw or change the color of the area of each white space. I did it this way but he doesn’t answer me because when I try to change the color of a single square he ends up changing either the whole row or the whole column.
for(var i = 0;i < linha;i++) {
for (var n = 0;n < coluna;n++) {
grid_x[i] = i * 40;
grid_y[n] = n * 40;
res_x[i] = i * 40;
res_y[n] = n * 40;
c[i] = false * i
dRs(grid_x[i],grid_y[n],grid_w,grid_h,1,"#747474",c[i])
}
}
function dRs(x,y,w,h,l,s,c) {
context.beginPath();
context.lineWidth= l;
context.strokeStyle= s;
context.rect(x,y,w,h);
context.stroke();
}
What do you mean
grid
? table? What makes the functiondRs()
?– Sergio
Sorry I forgot to explain in the topic. Drs() draws squares with Strokes, part c[i] is not part of the code. By grid I mean this: http://simcity1re.6te.net/ but without the drawing functions, this is a very old version of what I’m doing.
– deny.cavalli
And what are the parameters of this function? It’s not very clear what you want to do. You want to change the color inside the
for
or later?– Sergio
I want to change the color of each square separately per click. Example: if I click the middle square it will be black without turning any other square into black too.
– deny.cavalli
I prefer pure JS.
– deny.cavalli
Take a look here: http://jsfiddle.net/Kj8N7/
– Sergio
Sérgio, I wanted to thank you and ask one more thing I understood much of the code but I didn’t know what you did (apply,Concat and foreach) you can recommend me a site that shows me this type of function (I don’t know if it would be a function) Javascript standard?
– deny.cavalli