2009-06-09 3 views

答えて

4

あなたはcss:bottom:0pxを使用できるはずです。

+0

:固定; –

0

ユーザーがページを下にスクロールするときにブラウザウィンドウの下部にあるアイテムや、ページ下部に「スティック」するアイテムがありますか?

#2が必要な場合は、クロスブラウザのCSSメソッドをhereに設定します。

2

ブラウザの下部の位置は、クライアントからのドキュメントの高さに等しい0から下までの距離です。それは簡単のように計算することができます

 $(document).ready(function() { 
     var bottomPosition = $(document).height(); 
     alert(bottomPosition); 
    }); 

これは

+3

は、ドキュメントの高さであり、ウィンドウの最下部ではありません。またはウィンドウの高さでさえ、これは正解ではありません。 –

1

を支援している希望はこちらのページの一番下に滞在する必要があり、基本的な項目のための私のアプローチです。

最初にJavaScriptを使用してください。 "centerBottom"関数は、アクションが発生する場所です。

<script type="text/javascript"> 
/** 
* move an item to the bottom center of the browser window 
* the bottom position is the height of the window minus 
* the height of the item 
*/ 
function centerBottom(selector) { 
    var newTop = $(window).height() - $(selector).height(); 
    var newLeft = ($(window).width() - $(selector).width())/2; 
    $(selector).css({ 
     'position': 'absolute', 
     'left': newLeft, 
     'top': newTop 
    }); 
} 

$(document).ready(function(){ 

    // call it onload 
    centerBottom("#bottomThing"); 

    // assure that it gets called when the page resizes 
    $(window).resize(function(){ 
     centerBottom('#bottomThing'); 
    }); 

}); 
</script> 

私たちが動いているものを明確にするためのスタイルには、高さと幅がわからないと、項目を動かすのが難しい場合があります。 DIVの幅は、指定されていない場合は100%です。

<style type="text/css"> 
body { 
    margin: 0; 
} 
#bottomThing { 
    background-color: #600; color: #fff; height:40px; width:200px; 
} 
</style> 

とページの本文:

位置と一緒に
<body> 
<div id="bottomThing"> 
    Put me at the bottom. 
</div> 
</body> 
関連する問題