.scrollTop() 一个长的溢出-y:scroll div
我有一个具有以下设置的 div:
#check_in_history { 位置:绝对; 显示:块; 顶部:70 像素; 右:0; 底部:20px; 左:0; 溢出-x:隐藏; 溢出-y:滚动; -webkit-overflow-scrolling:触摸; 内边距:20px 0 0 0; 。
基本上,div 的高度取决于浏览器窗口的大小,并在您调整大小时发生变化
该 div 包含帖子,并且随着用户填充该列表,它会变得越来越长。
我想将其设置为每次用户添加帖子时它都会自动滚动到该列表的底部。我有一个 div,其 ID 位于该列表的底部,并且我在该 div 上附加了 post .before() 。
我已经尝试过这个功能。它适用于第一个帖子条目,但一旦添加第二个帖子,它就会在列表中滚动约 25%。:
$("#check_in_history").animate({scrollTop: $('#scroll_target').offset().top}, 1000, 'swing');
id:check_in_history 是溢出:滚动 div,#scroll_target 是该列表底部的 div 。
我怎样才能做到每次添加新帖子时它总是滚动到列表底部的“目标”div?
感谢您的帮助!
I have a div with these settings:
#check_in_history {
position: absolute;
display: block;
top: 70px;
right: 0;
bottom: 20px;
left: 0;
overflow-x: hidden;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
padding: 20px 0 0 0;
}
Basically, the div's height depends of the size of the browser window and changes when you resize it.
That div contains posts, and as users populate that list, it gets longer and longer.
I want to set it so that it automatically scrolls to the bottom of that list every time a user adds a post. I have a div with an ID at the bottom of that list, and I append the post .before() that div.
I have tried this function. It works for the first post entry, but as soon as you add a second one, it scrolls about 25% up the list.:
$("#check_in_history").animate({scrollTop: $('#scroll_target').offset().top}, 1000, 'swing');
id:check_in_history is the overflow:scroll div, and #scroll_target is the div at the bottom of that list.
How can I make it so that it always scrolls to that "target" div at the bottom of the list every time a new post is added?
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论