我在网上搜索并尝试了很多不同的方法,但不知道如何检测 iframe 的滚动。 iframe 源位于同一服务器上,与页面位于同一目录。这是初始代码:
$(document).ready(function(){
var iframe = $('#iframeId');
iframe.load(function(){
$(this).scroll(function() {
alert('scrolling');
});
});
iframe.attr('src','document.html');
});
我尝试过改变:
$(this).scroll(function() {
对于所有这些选项:
$($(this).contents()).scroll(function() {
$($(this).contents().get(0)).scroll(function() {
$($(this).contents().find('html')).scroll(function() {
$($(this).contents().find('body')).scroll(function() {
$($(this).get(0).contentWindow).scroll(function() {
我还尝试添加到 iframe html 标签:
onscroll="alert('scrolling')"
似乎没有什么可以触发。有任何想法吗?谢谢。
最佳答案
纯 JavaScript :
<script type="text/javascript">
window.onload = function() {
var frm = document.getElementById("iframeId").contentWindow;
frm.onscroll = function(){
alert("scrolling...");
}
}
</script>
关于javascript - iFrame 滚动事件检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29704982/