Помислете за просто платно като
$(document).ready(function(){
draw();
});
function draw() {
var canvas = document.getElementById("canvas");
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect (10, 10, 55, 50);
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
ctx.fillRect (30, 30, 55, 50);
}
}
Как мога да въведа променлива във функцията jQuery, за да нарисувам няколко платна с дефинирана променлива (напр. набор от цветове).
Всъщност искам да заменя идентификатора на платното и неговите опции (като цвят) с променлива, предоставена от draw(variables)
, напр.draw(canvas_id, color, ...)
.
Пример: (за създаване на няколко платна върху различни DOM елементи)
function draw(ccc) {
var canvas = document.getElementById(ccc);
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect (10, 10, 55, 50);
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
ctx.fillRect (30, 30, 55, 50);
}
}
draw(canvas1);
draw(canvas2);
$(document).ready(function(){ draw(); });
? - person xiaoyi   schedule 19.05.2012draw(list of variables)
- person Googlebot   schedule 19.05.2012$(document).ready(function(){
; благодаря за пояснението. - person Googlebot   schedule 19.05.2012