gpt4 book ai didi

jquery - 滚动时如何定位框

转载 作者:太空宇宙 更新时间:2023-11-04 15:09:25 25 4
gpt4 key购买 nike

如何定位绿色框,以便在使用 jQuery 滚动超过其高度时,框的底部与可用空间的底部对齐。

<div class="content">
<div class="left">
</div>
<div class="right">
</div>
</div>

.content { width: 400px; position: relative; height: 200px; overflow-y: auto; overflow-x: hidden; border: 1px solid gray; }
.left { position: absolute; left: 0; width: 200px; background: red; height: 400px; }
.right { position: absolute; right: 0; width: 200px; height: 100px; background: green; }


$('.content').scroll(function(){
//how to position green box so the bottom of the box
//is aligned to bottom of space available
});

http://jsfiddle.net/chovy/ryFGK/4/

最佳答案

是这样的吗?

http://jsfiddle.net/ryFGK/5/

<div class="content">
<div class="left">
</div>
<div class="right">
</div>
</div>

$('.content').bind('scroll', function(e) {
var content = $(this);
var scrollTop = content.scrollTop();
var green = $('.right');
console.log('Top: ' + green.position().top + ', ScrollTop: ' + scrollTop);
if (scrollTop > green.height()) {
green.css({top: scrollTop + content.height() - green.height()});
} else {
green.css({top: 0});
}
});

关于jquery - 滚动时如何定位框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15508558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com