【问题标题】:scrolling ajax load more records feature within an iframe滚动 ajax 在 iframe 中加载更多记录功能
【发布时间】:2014-08-19 15:24:25
【问题描述】:

我想做一个滚动 ajax 加载更多记录的功能,但是......

我在外部网站的 iframe 中。父站点自动将 iframe 的高度设置为其内容(我的内容)的高度。如何检测用户是否向下滚动父站点直到 iframe 竞争结束?

我在网络上尝试了几种解决方案,但它们都不能在 iframe 中工作。

这里有一个小提琴示例:http://jsfiddle.net/57oyyoc7/1/

$(window).scroll(function() {
    if($(window).scrollTop() == $(document).height() - $(window).height()) {
           // ajax call get data from server and append to the div
        console.log("load more");
    }
});

【问题讨论】:

  • 你不能。在这种情况下,它必须是来自父级的 javascript 才能检测到这一点。

标签: javascript jquery iframe


【解决方案1】:

实际上有一种方法可以做到这一点。我在评论中没有正确理解您的问题:

$(parent.window).scroll(function(e){
    if($(window.parent.document).scrollTop() >= $('html').height()) {
        console.log("load more from parent");
    }
});

Demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    相关资源
    最近更新 更多