如何使用jquery检查iframe html文件滚动是否达到底部

How to check iframe html file scroll is reached to bottom or not using jquery

本文关键字:是否 滚动 底部 文件 html 何使用 jquery 检查 iframe      更新时间:2023-09-26

我在asp.net MVC3,中有下面的查看页面

@using (Html.BeginForm())
{
<p>
test test
test test
test test
test test
test test
</p>
<article border="0" >
<iframe src ="@Url.Content("~/Content/test.html")" width="100%" height="300px" id="iframeContent"></iframe>
</article>
<p>
test test
test test
test test
test test
test test
</p>
<table>
<tr>
<td>
sample data
</td>
</tr>
</table>
}

iframe-src-html文件有点大,所以它有滚动功能。我想检查html文件滚动是否到达底部。如果它到达底部,我需要做一些验证。

我可以使用下面的jquery对整个页面进行查询,但我不知道如何只对iframe滚动内容进行查询。有什么建议吗?

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
       alert("Bottom Reached!");
   }
});

试试这个:

$('iframe').bind('load',function(){
    var $win=$('iframe').get(0).contentWindow;
    $win.scroll(function() {
       if($win.scrollTop() + $(window).height() == $(document).height()) {
           alert("Bottom Reached!");
       }
    });
});