Bootstrap affix stop working after scroll to bottom of the page

久未见 提交于 2019-12-30 06:28:13

问题


I have long page with fixed left sidebar :

<div id="sidebar">
    <ul>
        <li>menu 1</li>
        <li>menu 2</li>
        <li>menu 3</li>
        <li>menu 4</li>
        <li>menu 5</li>
        <li>menu 6</li>
        <li>menu 7</li>
    </ul>
</div>

and js for affix:

$("#sidebar").affix({offset: {top: 0, bottom:420} });

I have and footer which is with height:390px. When I first time scroll to the bottom of the page and try to scroll up the sidebar returns to its first position (to the top of the page) and it is not with position:fixed, anymore. It is with inline style position:relative, added with Bootstrap JS. When I scroll to the top I see class changed to affix-top. Every other scroll page position, the class is affix, even if it is of the bottom of the page and sidebar stay with position:relative. If I use only :

$("#sidebar").affix({offset: {top: 0} });

, without bottom, it works fine, but I need bottom, because of the footer.

Where can be the problem ?


回答1:


As the docs suggest adding position: absolute to the .affix-bottom appears to solve this problem.

So you need the css:

#sidebar.affix-bottom {
  position: absolute;
}

Bootply



来源:https://stackoverflow.com/questions/43101649/bootstrap-affix-stop-working-after-scroll-to-bottom-of-the-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!