当您滚动时,我有一个侧边栏。现在我希望它在到达某个 div 时停止(并修复)。

为了说明。
发生了什么:
http://postimg.org/image/l1n0djb0n/

我想要的是:
http://postimg.org/image/5evr05x8n/

到达最后一个内容的底部时,我需要停止 float (滚动)。

我怎样才能做到这一点?

CSS:

#sidebar.affix-top { 
position: static; 
margin-top:0px;  
} 
 
#sidebar.affix { 
position: fixed; 
top:49px; 
} 

HTML:
 <div id="sidebar" class="sidebar_package"> 
 info for sidebar 
 
 <div class="hiddenpackage_c2a"> 
     more content 
 </div> 
 
 </div> 

JS:
//Side menu floater 
$('#sidebar').affix({ 
      offset: { 
        //top: $('header').height() 
        top:185 
      } 
}); 

请您参考如下方法:

您可以使用底部偏移

$('#sidebar').affix({ 
    offset: { 
       top: 180, 
       bottom: $('#bottom-div').outerHeight(true) 
   } 
}); 

并添加以下css
.affix-bottom {  
    position: absolute;  
} 


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!