在iframe中检测滚动到底部? [英] Detect scroll to bottom in an iframe?
问题描述
我正在使用以下事件来检测滚动时是否到达页面底部:
I'm using the following event to detect if the bottom of a page is reached when scrolling :
$(window).scroll(function() {
if($(window).scrollTop() == $(document).height()-$(window).height())
alert('Bottom reached');
}
});
这在正常页面上正常工作,但现在我希望它在 iframe内 内的页面上工作.必须在iframe的页面内声明此事件.
但是window
指向包含iframe的页面,所以我不能使用它.
This works fine on a normal page, but now I want this to work on a page that is inside an iframe. This event must be declared inside the page in the iframe.
But window
points to the page that contains the iframe, so I can't use that.
有什么想法吗?
推荐答案
var currAgreementTab = this.get('parentController').get('currAgreement'); var contractContainer = Ember.$('div#marginContractContainer'); var iframe = contractContainer.children(currAgreementTab.element)[0] .contentWindow;
var currAgreementTab = this.get('parentController').get('currAgreement'); var contractContainer = Ember.$('div#marginContractContainer'); var iframe = contractContainer.children(currAgreementTab.element)[0].contentWindow;
if (iframe) {
iframe.onscroll = function() {
var scrolledHeight = Ember.$(iframe).height() === Ember.$(iframe.document).innerHeight() ? Ember.$(iframe).height() : Ember.$(iframe.document).innerHeight() - Ember.$(iframe).height();
if (Ember.$(iframe).scrollTop() === scrolledHeight) {
var currAgreementTab = that.get('parentController').get('currAgreement');
Ember.set(currAgreementTab, 'checkDisabled', false);
}
}
}
这篇关于在iframe中检测滚动到底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!