Style backgroundRepeatプロパティ
Style オブジェクト
定義と用法
backgroundRepeat プロパティは背景画像の繰り返し方法を設定または返します。
構文
backgroundRepeat プロパティを設定:
Object.style.backgroundRepeat="repeat|repeat-x|repeat-y|no-repeat|inherit"
backgroundRepeat プロパティを返す:
Object.style.backgroundRepeat
| 值 | 説明 |
|---|---|
| repeat | デフォルト。背景画像を垂直および水平方向に繰り返します。 |
| repeat-x | 背景画像を水平方向に繰り返します。 |
| repeat-y | 背景画像を垂直方向に繰り返します。 |
| no-repeat | 背景画像を繰り返しません。 |
| inherit | background-repeat プロパティの設定は親要素から継承されます。 |
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザが backgroundRepeat プロパティをサポートしています。
注意:IE7 以前のバージョンは "inherit" 値をサポートしていません。IE8 は !DOCTYPE が指定されている場合のみ "inherit" をサポートします。IE9 は "inherit" をサポートしています。
例
例
背景画像を垂直方向に繰り返すように設定する:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</title>
<style type="text/css">
body{
background:#f3f3f3 url('img_tree.png');
}
</style>
<script>
function displayResult(){
document.body.style.backgroundRepeat="repeat-y";
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">背景画像を垂直に繰り返す</button>
<br>
<h1>Hello World!</h1>
<p>これは段落です</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</title>
<style type="text/css">
body{
background:#f3f3f3 url('img_tree.png');
}
</style>
<script>
function displayResult(){
document.body.style.backgroundRepeat="repeat-y";
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">背景画像を垂直に繰り返す</button>
<br>
<h1>Hello World!</h1>
<p>これは段落です</p>
</body>
</html>
試してみる »
Style オブジェクト その他の拡張