フィドルの例: http://jsfiddle.net/wmnWc/5/
ビューポート ウィンドウのサイズを調整して、何を達成しようとしているのかを確認します。
私のコードでわかるように、フォーム コンテナーの外側の高さまでの min-height 値を使用して、コンテナーの高さを設定しました。これは、背景画像を表示したまま、フォームの自然な高さまでスクロールできるようにしたいためです。
また、画像が常に自然な比率を維持する必要もあります。ご覧のとおり、これが私がやろうとしたことです。
サンプル写真の寸法:
- 幅: 2560px
- 高さ: 1709px
コード:
$(window).bind("resize.browsersize", function () {
var viewportHeight = $(window).height(),
viewportWidth = $(window).width(),
loginHeight = $('#login').outerHeight(),
containerHeight = $('.background-photo').height(),
containerWidth = $('.background-photo').width(),
ratioHeight = 1,
ratioWidth = 1.497;
$(".background-photo").css({
'width': viewportWidth + 'px',
'height': viewportHeight + 'px',
'min-height': loginHeight + 'px'
});
if (containerHeight > containerWidth) {
$(".background-photo img").css({
'height': containerHeight + 'px',
'width': containerHeight * ratioWidth + 'px',
'max-width': containerHeight * ratioWidth + 'px'
});
} else if (containerWidth > containerHeight) {
$(".background-photo img").css({
'width': containerWidth + 'px',
'height': 'auto',
'max-width': containerWidth + 'px'
});
}
}).trigger("resize.browsersize");
前もって感謝します。
ジョシュ