Style backgroundAttachment属性
- 前のページ background
- 次のページ backgroundColor
- 上層に戻る HTML DOM Styleオブジェクト
定義と使用方法
backgroundAttachment
属性の設定や返り値が背景画像が内容に合わせてスクロールするか固定されるかを決定します。
も参照してください:
HTMLスタイル:background属性
CSSチュートリアル:CSS 背景
CSSリファレンスマニュアル:background-attachment属性
例
例1
背景画像を固定(スクロールしません)に設定:
document.body.style.backgroundAttachment = "fixed";
例2
DIV要素上でscrollとlocalを選択:
document.getElementById("myDIV").style.backgroundAttachment = "local";
例3
scrollとfixedの切り替え:
var x = document.body.style.backgroundAttachment; document.body.style.backgroundAttachment = (x == "scroll")? "fixed":"scroll";
例4
background-attachment属性の値を返します:
alert(document.body.style.backgroundAttachment);
文法
backgroundAttachment属性の返り値:
object.style.backgroundAttachment
backgroundAttachment属性の設定:
object.style.backgroundAttachment = "scroll|fixed|local|initial|inherit"
属性値
値 | 説明 |
---|---|
scroll | 背景は要素に合わせてスクロールします。デフォルトです。 |
fixed | 背景はビューポートに対して固定されます。 |
local | 背景は要素の内容に合わせてスクロールします。 |
initial | この属性をデフォルト値に設定します。参照してください initial。 |
inherit | 親要素からこの属性を継承します。参照してください inherit。 |
技術的な詳細
デフォルト値: | scroll |
---|---|
返り値: | 文字列で、背景画像がどのようにドキュメント内のオブジェクトに追加されるかを示します。 |
CSSバージョン: | CSS1 |
ブラウザのサポート
backgroundAttachment
CSS1(1996)の機能です。
すべてのブラウザが完全にサポートしています:
Chrome | Edge | Firefox | Safari | Opera | IE |
---|---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera | IE |
サポート | サポート | サポート | サポート | サポート | サポート |
- 前のページ background
- 次のページ backgroundColor
- 上層に戻る HTML DOM Styleオブジェクト