スタイルbackgroundAttachmentプロパティ
例
固定する背景画像を設定します(スクロールしません):
document.body.style.backgroundAttachment = "fixed";
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
backgroundAttachmentプロパティは、背景画像をコンテンツと一緒にスクロールするか、修正するかを設定または返します。
ブラウザのサポート
表の数字は、プロパティを完全にサポートする最初のブラウザバージョンを示しています。
Property | |||||
---|---|---|---|---|---|
backgroundAttachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
構文
backgroundAttachmentプロパティを返します。
object.style.backgroundAttachment
backgroundAttachmentプロパティを設定します。
object.style.backgroundAttachment = "scroll|fixed|local|initial|inherit"
プロパティ値
Value | Description |
---|---|
scroll | The background scrolls along with the element. This is default |
fixed | The background is fixed with regard to the viewport |
local | The background scrolls along with the element's contents |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
技術的な詳細
デフォルト値: | スクロール |
---|---|
戻り値: | ドキュメント内のオブジェクトに背景画像がどのように添付されているかを表す文字列 |
CSSバージョン | CSS1 |
その他の例
例
DIV要素でスクロールとローカルのどちらかを選択します。
document.getElementById("myDIV").style.backgroundAttachment = "local";
例
スクロールと固定を切り替えます。
var x = document.body.style.backgroundAttachment;
document.body.style.backgroundAttachment = (x == "scroll")? "fixed":"scroll";
例
background-attachmentプロパティの値を返します。
alert(document.body.style.backgroundAttachment);
関連ページ
CSSチュートリアル:CSSの背景
CSSリファレンス:background-attachmentプロパティ
HTML DOMリファレンス:背景プロパティ