简体   繁体   English

将div的底部固定到滚动屏幕的底部

[英]fixing the bottom of div to the bottom of screen on scroll

hello all i was wondering how to achieve this. 你好,我想知道如何实现这一目标。 i have a page in which there are three divs floating left and have width as 20% 60% and 19% all the divs are of veritable height but always the height of middle one is far greater then the other two . 我有一个页面,其中有三个div浮动,其宽度分别为20%,60%和19%,所有div的高度都很高,但中间一个的高度总是远大于其他两个。 so want that whenever i scroll the page to see the bottom of middle div the bottom of other div stick to the screen as it is and automatically gets released when scrolled up to top. 所以希望每当我滚动页面以查看中间div的底部时,其他div的底部都照原样贴在屏幕上,并在滚动到顶部时自动释放。

i know this is possible here is what i just noticed in a site http://resources.infosecinstitute.com/checking-out-backdoor-shells/ the extreme right div is similer example of what is want. 我知道这是可能的,这就是我刚刚在网站http://resources.infosecinstitute.com/checking-out-backdoor-shells/上注意到的/最右端的div是所需的类似示例。

can anyone please help me to achieve this. 谁能帮我实现这一目标。

 onscroll event can be applied here by js like 
 onscroll if // check if the div is about to end then fix it as it is 
  else // release it.
$( "#target" ).scroll(function() {
                    $( "#div_left" ).css( {'position': 'fixed' , 'bottom' : '20px'} );
                    $( "#div_right" ).css( {'position': 'fixed' , 'bottom' : '20px'} );
});

Demo 演示版

js js

$(window).scroll(function () {
    if ($(this).scrollTop() > $('#test').height()) {
        $('#test').addClass('fixed');
    } else {
        $('#test').removeClass('fixed');
    }
});

css 的CSS

body, html {
    height:1000px;
    position:relative;
    margin:0;
    padding:0;
}
#test {
    height:50px;
    background-color:blue
}
.fixed {
    position:fixed;
    bottom:0;
    z-index:2;
    width:100%;
}

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

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