HTML DOM Style backgroundAttachment 屬性

2018-08-04 20:40 更新

Style backgroundAttachment 屬性

Style 對象參考手冊 Style 對象

定義和用法

backgroundAttachment 屬性設置或返回背景圖像是否固定或者隨著頁面的其余部分滾動。

語法

設置 backgroundAttachment 屬性:

Object.style.backgroundAttachment="scroll|fixed|local"

返回 backgroundAttachment 屬性:

Object.style.backgroundAttachment

描述
scroll 背景隨著元素一起滾動。這是默認。
fixed 背景保持固定。
local 背景隨著元素的內容一起滾動。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持 backgroundAttachment 屬性。


實例

實例

設置背景圖像為固定(不滾動):

<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>

嘗試一下 ?


實例

更多實例

滾動和固定之間切換
滾動和固定的 backgroundAttachment 之間的切換。


Style 對象參考手冊 Style 對象
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號