だから私はいくつかの基本的なキャンバスとを持っていて<input type="color">
、色の特定の形の色を変えたいと思ってon change
います。
これが私のコードです
var colorRect = '#000';
var ball = document.getElementById("canvas");
var ctx = ball.getContext("2d");
var ctx1 = ball.getContext("2d");
ctx1.fillStyle = colorRect;
ctx1.fillRect(0,0,200,200);
ctx1.save();
//Left eye
ctx.fillStyle = '#fff';
ctx.fillRect(50,80,10,10);
//Right eye
ctx.fillStyle = '#fff';
ctx.fillRect(150,80,10,10);
//Nose
ctx.fillStyle = '#fff';
ctx.fillRect(100,110,10,20);
//Mouth
ctx.fillStyle = 'red';
ctx.fillRect(60,150,100,10);
$('#favcolor').on('change',function(){
colorRect = $(this).val();
ctx1.fillStyle = $(this).val();
ctx1.fillRect(0,0,200,200);
});
ここでライブを見ることができます:http: //jsbin.com/inewum/1問題は、目と口が見えなくなったため、すべてが上書きされると思うことです...スタイルを更新したいだけですそれ。