iphoneやAndroid2.3で背景画像固定を実現する方法のメモ。(要jQuery)
まずは横幅640px
縦幅適当(iPhoneの縦の高さをカバーできるくらい)の画像を用意。
html
<html> <header> <!--略--> </header> <body> <div id="main"> <p>コンテンツ</p> </div> </body> </html>
js
これで背景画像を追加してます
$(function(){ $('body').prepend('<img src="img/bg_sub02.jpg" id="allBg">'); });
css
背景画像をfixedさせて、z-indexをメインのコンテンツより下に。
メインのコンテンツを背景画像よりz-index上にしてposition:relativeする。
横幅を100%にするかはお好みで。
/*body*/ body{ background-color: #000; } /*背景の設定*/ body #allBg{ position: fixed; top: 0; left: 0; width: 100%; z-index: 1; } #main{ position: relative; top: 0; left: 0; z-index: 2; }