使用 jquery 滚动 div 时加载内容

发布于 2024-08-29 01:47:52 字数 548 浏览 2 评论 0 原文

我需要在滚动 div 时加载内容,而不是窗口。 这是我的 CSS 代码:

#sidebar{
 width:30%;
 float:right;
 height:455px;
}
#video_list{
  height:100%;
  overflow:auto;
}

这是我的 html 代码:

<div id="sidebar" >
 <!-- other -->
 <div id="video_list">
 </div>
</div>

Video_list 是可滚动的,内容是通过 ajax 调用加载的。 当我转到滚动条的末尾时,我需要再次加载内容。 如何确定可滚动 div 的高度? 我尝试过这个:

if ($("#video_list").scrollTop()==$("#video_list").height()){
  loadContent();
 }

但它不起作用!

I need to load content while scrolling a div, not window.
That's my CSS code:

#sidebar{
 width:30%;
 float:right;
 height:455px;
}
#video_list{
  height:100%;
  overflow:auto;
}

And this is my html code:

<div id="sidebar" >
 <!-- other -->
 <div id="video_list">
 </div>
</div>

Video_list is scrollable and the content is loaded by ajax call.
When I go to the end of scrollbar i need to load content again.
How can i determine the height of scrollable div ?
I tried this:

if ($("#video_list").scrollTop()==$("#video_list").height()){
  loadContent();
 }

but it doesn't work !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爺獨霸怡葒院 2024-09-05 01:47:52

要获取滚动高度,您可以这样做:

$("#video_list")[0].scrollHeight;

To get the scroll height you can do this:

$("#video_list")[0].scrollHeight;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文