Image widthプロパティ
Image オブジェクト
定義と使い方
width プロパティは、画像の width 属性の値を設定または返します。
width プロパティは、画像の幅を指定します。
構文
imageObject.width=pixels
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザは width プロパティをサポートしています。
例
例
画像の高さと幅を変更:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル チュートリアル(example.com)</title>
<script>
function changeSize(){
document.getElementById("compman").height="250";
document.getElementById("compman").width="300";
}
</script>
</head>
<body>
<img id="compman" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSize()" value="画像サイズを変更">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル チュートリアル(example.com)</title>
<script>
function changeSize(){
document.getElementById("compman").height="250";
document.getElementById("compman").width="300";
}
</script>
</head>
<body>
<img id="compman" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSize()" value="画像サイズを変更">
</body>
</html>
試してみる »
Image オブジェクトその他の拡張