Style backgroundAttachment 屬性
Style 對(duì)象定義和用法
backgroundAttachment 屬性設(shè)置或返回背景圖像是否固定或者隨著頁(yè)面的其余部分滾動(dòng)。
語(yǔ)法
設(shè)置 backgroundAttachment 屬性:
Object.style.backgroundAttachment="scroll|fixed|local"
返回 backgroundAttachment 屬性:
Object.style.backgroundAttachment
值 | 描述 |
---|---|
scroll | 背景隨著元素一起滾動(dòng)。這是默認(rèn)。 |
fixed | 背景保持固定。 |
local | 背景隨著元素的內(nèi)容一起滾動(dòng)。 |
瀏覽器支持
所有主要瀏覽器都支持 backgroundAttachment 屬性。
實(shí)例
實(shí)例
設(shè)置背景圖像為固定(不滾動(dòng)):
<html>
<head>
<style type="text/css">
body
{
background:#f3f3f3 url('img_tree.png') no-repeat right top;
}
</style>
<script>
function displayResult()
{
document.body.style.backgroundAttachment="fixed";
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">Set background image to be fixed</button>
<br>
<h1>Hello World!</h1>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
<head>
<style type="text/css">
body
{
background:#f3f3f3 url('img_tree.png') no-repeat right top;
}
</style>
<script>
function displayResult()
{
document.body.style.backgroundAttachment="fixed";
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">Set background image to be fixed</button>
<br>
<h1>Hello World!</h1>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
嘗試一下 ?
更多實(shí)例
滾動(dòng)和固定之間切換
滾動(dòng)和固定的 backgroundAttachment 之間的切換。
Style 對(duì)象
更多建議: