2011-05-14 112 views
1

如何让我的页面浮动DIV?目前,我有它的设置是这样的:http://g2n.us/Dev/TheHabbos_6975/ 我可以使用下面的CSS这样做: 代码:DIV浮动页面

.stayStill { 
    position: fixed; 
    width: 300px; 
} 

但我怎样才能得到它,当标题滚动走,右边的DIV向上移动和住宿距离顶部10像素并且与页面一起滚动,除非标题在那里?

回答

0

这个答案使用jQuery

你可以把这个在您的$.ready()功能

var int_header_height = 10; //put pixel value height of header here 
if ($(document).scrollTop() <= int_header_height) { 
    $('div.stayStill').css('position','absolute').css('top','0px'); 
} else { 
    $('div.stayStill').css('position','fixed').css('top','10px'); 
} 

这还假定div位于标题下方的position: relative元素中。否则,您应该将.css('top','0px')更改为.css('top',int_header_height + 'px')