Атрибут width
Описание
Задает ширину холста. По умолчанию 100px.
Синтаксис
<canvas width='размер'></canvas>
Пример
<!DOCTYPE html>
<html lang='ru'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Document</title>
</head>
<body>
<canvas style='background-color: lightblue;' id='smile' width='200' height='200'>
<p>Canvas не поддерживается браузером.</p>
</canvas>
<script>
var drawingCanvas = document.getElementById('smile');
if(drawingCanvas && drawingCanvas.getContext) {
var context = drawingCanvas.getContext('2d');
// Рисуем окружность
context.strokeStyle = '#000';
context.fillStyle = '#ffcd03';
context.beginPath();
context.arc(100,100,50,0,Math.PI*2,true);
context.closePath();
context.stroke();
context.fill();
// Рисуем левый глаз
context.fillStyle = '#000000';
context.beginPath();
context.arc(84,90,8,0,Math.PI*2,true);
context.closePath();
context.stroke();
context.fill();
// Рисуем правый глаз
context.beginPath();
context.arc(116,90,8,0,Math.PI*2,true);
context.closePath();
context.stroke();
context.fill();
// Рисуем рот
context.beginPath();
context.moveTo(70,115);
context.quadraticCurveTo(100,130,130,115);
context.quadraticCurveTo(100,150,70,115);
context.closePath();
context.stroke();
context.fill();
}
</script>
</body>
</html>
Читайте также
Тег <td>. Атрибут bordercolor
Указывает цвет рамки.
Тег <area>. Атрибут href
Задает адрес, по которому он должен перейти.<br>По умолчанию новый документ будет загружать...
Тег <iframe>. Атрибут marginwidth
Делает отступы от содержания до границы фрейма по горизонтали, т.е. слева и справа.
Тег <th>. Атрибут abbr
Краткое описание содержимого ячейки.
Тег <meter>. Атрибут high
Определяет предел, при достижении которого значение считается высоким.