Style backgroundRepeat 屬性

定義和用法
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>IT研修(xuhuhu.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>IT研修(xuhuhu.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>
