如何监听IFRAME 滚动的事件

OopsJeff 2010-10-15 07:55:54
页面中有一个iframe. 想在iframe滚动的时候,触发一些JS. 如何监听这个iframe滚动?
...全文
1089 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
OopsJeff 2010-10-18
  • 打赏
  • 举报
回复
比如以下代码. 不加入iframe 就正常可以同步左边的滚轮到右边.



<html>
<head>
<style>
DIV {width:200;height:200;border:solid 1px;overflow-x:hidden;overflow-y:scroll;}
body {margin:0}
</style>
</head>
<body>
<div onscroll="ToScroll.scrollTop = this.scrollTop;">

<table border="1" width="99%" height="99%">
<tr height="1000">
<td width="99%">

</td>
</tr>
</table>



</div>

<div id="ToScroll" style="left:320px;position:absolute;top:0px;">
<table border="1" width="99%" height="99%">
<tr height="1000">
<td width="99%">

</td>
</tr>
</table>


</div>
</body>
</html>



加入iframe 就不行了



<html>
<head>
<style>
DIV {width:200;height:200;border:solid 1px;overflow-x:hidden;overflow-y:scroll;}
body {margin:0}
</style>
</head>
<body>
<div onscroll="ToScroll.scrollTop = this.scrollTop;">

<table border="1" width="99%" height="99%">
<tr height="1000">
<td width="99%">
<iframe name="queryListFrame2" src="http://www.hao123.com"/>
</td>
</tr>
</table>



</div>

<div id="ToScroll" style="left:320px;position:absolute;top:0px;">
<table border="1" width="99%" height="99%">
<tr height="1000">
<td width="99%">
<iframe name="queryListFrame2" src="http://www.hao123.com"/>
</td>
</tr>
</table>


</div>
</body>
</html>


zoujp_xyz 2010-10-17
  • 打赏
  • 举报
回复
iframe src="1.html"

1.html:
<script>
var fun=function(){

}
</script>
<body onscroll="fun()"></body>
OopsJeff 2010-10-17
  • 打赏
  • 举报
回复
能更详细点吗? 最好给个例子
孟子E章 2010-10-15
  • 打赏
  • 举报
回复
在iframe的里面
<body onscroll=""实现

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧