Сообщение от alexander555
|
я нуб
|
так писали бы в раздел работа
<script type="text/javascript">
window.onload = function() {
var canvas = document.getElementById('canvas'),
array = [0, 220, 400],
pol = document.getElementsByName('pol'),
size = document.getElementsByName('size'),
button = document.getElementsByName('button')[0],
d_height = 50,
d_width = 50,
i = pol.length, j,
ctx = canvas.getContext('2d');
ctx.fillStyle = "rgba(11,118, 81, 0.5)";
ctx.fillRect(0, 0, d_width, d_height);
while(i--) {
pol[i].onchange = function(i) {
return function() {
j = i;
};
}(i);
button.onclick = function(i) {
return function() {
var width = size[0].value, height = size[1].value;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillRect(array[j], 0, size[0].value == '' ? d_width : width, size[1].value == '' ? d_height : height);
};
}(i);
}
};
</script>
<form name="forma">
<input type="radio" name="pol" checked="checked" />Left <br />
<input type="radio" name="pol" />Center <br />
<input type="radio" name="pol" />Right <br />
<input type="text" name="size" value="50" /> Width <br />
<input type="text" name="size" value="50" /> Height
<input type="button" name="button" value="click" />
</form>
<canvas id='canvas' width="500" height="500">Обновите браузер</canvas>