简体   繁体   English

如何让侧边栏向上移动

[英]How do I get the sidebar to move up

I have this page and I want the sidebar to slide down with the user and it works well but if you are on a small screen like 1024 * 768 you will not see the bottom.我有这个页面,我希望侧边栏与用户一起向下滑动,并且效果很好,但是如果您在像 1024 * 768 这样的小屏幕上,您将看不到底部。 Here is some of the code I used to make the sidebar work.这是我用来使侧边栏工作的一些代码。 Any suggestions on how I can change this behavior.关于如何改变这种行为的任何建议。

$(window).scroll(function(){ 
    sidebar_position();
});
$(window).resize(function(){ 
    sidebar_position();
});


function sidebar_position(){
    var w_width = ($(window).width() -1000) /2;
    $('#sidebar').css('left', w_width);

    var sidebar_height = $('#sidebar').outerHeight();
    var content_height = $('#widecolumn').outerHeight();
    var w_height = $(window).height();

    if ( sidebar_height > w_height) {
        $('#sidebar').css('position', 'absolute');
    } else {
        $('#sidebar').css('position', 'fixed');
    };

    if (sidebar_height > content_height) {
        content_height = sidebar_height;
        $('#widecolumn').css('min-height', content_height);
    };


    if($.browser.msie && $.browser.version == 6 ){
        $(window).scroll(function(){ 
            $('#sidebar').css({
                top: $(window).scrollTop()
            });
        })
    }
}

I am sort of lost of what to do next....and how to fix this我有点不知道下一步该做什么......以及如何解决这个问题

Hm small screens are a problem either way since the sidebar is almost 600 px high so on netbooks it probably won't fit in the browser window at all.嗯,无论哪种方式,小屏幕都是一个问题,因为侧边栏几乎是 600 像素高,所以在上网本上它可能根本不适合浏览器 window。

But you could leave the sidebar on position absolute until the sidebar reaches the top when scrolling and then switch to position fixed so it stays at the top of the screen.但是您可以将侧边栏保留在 position 绝对位置,直到侧边栏在滚动时到达顶部,然后切换到 position 固定,使其保持在屏幕顶部。
That way it will use the available screen height这样它将使用可用的屏幕高度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM