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>菜鳥教程(runoob.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 對象