如果你需要保持它在底部用的,因爲這 jQuery的
$(document).scroll(function() {
var objectTop = $('#shopping-cart').position().top;
var objectHeight = $('#shopping-cart').outerHeight();
var windowScrollTop = $(window).scrollTop();
var windowHeight = $(window).height();
if((objectTop+objectHeight) <= $('html').outerHeight())
$('#'+cont).css('top', (windowScrollTop+windowHeight)- objectHeight);
else
$('#'+cont).css('top', $('html').outerHeight()- objectHeight);
});
級的CSS
#shopping-cart{
width: 100%;
height: 50px;
position: absolute;
left: 0px;
bottom: 0px;
}
如果你需要保持它在上面使用,因爲這 jQuery的
$(document).scroll(function() {
var objectHeight = $('#shopping-cart').outerHeight();
var windowScrollTop = $(window).scrollTop();
var windowHeight = $(window).height();
$('#shopping-cart').css('top', windowScrollTop);
});
的CSS
#shopping-cart{
width: 100%;
height: 50px;
position: absolute;
left: 0px;
top: 0px;
}
它會做魔術和不忘記保持你的風格位置和一件事它不工作與Internet Explorer 8.0.7
這是一個很好的,光滑的做法。 +1 – Dutchie432 2011-03-11 13:50:00
它不像荷蘭人那樣「彈跳」,但它確實是「Ask」網站上的框。 – michelgotta 2011-03-11 13:58:55
如果您不需要「粘性」或「反彈」效果,這實際上可能比我的方法更好。在某些情況下,我的方法會導致閃爍。見http://jsfiddle.net/Jaybles/C5yWu/4/ – Dutchie432 2011-03-11 16:15:30