2009-06-09 87 views

回答

4

你應該可以使用css:bottom:0px;

+0

一起:固定; – 2013-06-21 15:19:15

0

當用戶向下滾動頁面時,是否希望某些項目停留在瀏覽器窗口的底部,或者某個項目「粘」到頁面的底部,哪裏可能?

如果你想#2,可以找到一個跨瀏覽器的CSS方法here

2

瀏覽器的底部位置是從頂部到底部的距離:0到底部,它等於客戶端文檔的高度。它可以很容易地計算如下:

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

希望這是幫助

+3

即文檔的高度,而不是窗口的底部。甚至窗戶的高度,這不是正確的答案。 – 2013-06-21 15:18:57

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> 
與位置