通过滚动页面保持侧面导航固定

Stu*_*son 5 css jquery scroll

我有一个客户网站 - www.stagecraft.co.uk,他们希望当您向下滚动页面时,租用页面(较长页面)上的导航仍然存在.我有一个快速前进(不是现场),位置固定,但这样做左侧导航从窗口顶部约200px左右.滚动时何时在窗口顶部获取它?

提前致谢....

pei*_*rix 3

仅当滚动达到某个点时,您可以将其位置固定:

$(window).scroll(function() {
    if ($(this).scrollTop() > 200) { //I just used 200 for testing
        $("#tester").css({ "position": "fixed", "top": 0 });
    } else {
        $("#tester").css({ "position": "absolute", "top": "200px" }); //same here
    }               
});
Run Code Online (Sandbox Code Playgroud)

div 的 CSS 如下:

#tester {
    position: absolute;
    right: 20px;
    top: 200px;
    height: 200px;
    width: 100px;
    background: red;
}
Run Code Online (Sandbox Code Playgroud)