【问题标题】:How to check iframe html file scroll is reached to bottom or not using jquery如何检查iframe html文件滚动是否到达底部或不使用jquery
【发布时间】:2014-10-29 06:23:58
【问题描述】:

我在 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!");
   }
});

【问题讨论】:

    标签: javascript jquery html css iframe


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • 尝试将其添加到文档就绪事件。调用函数时,可能 iframe 不在 dom 中
    猜你喜欢
    • 2011-08-15
    • 1970-01-01
    • 2014-02-08
    • 2011-12-04
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 2010-12-25
    相关资源
    最近更新 更多