繁体   English   中英

jQuery哪个事件比这更好?

[英]Jquery which event is better than this?

我在iframe中有html页面(父页面)。 当您在iframe中导航时(重新加载iframe的页面或单击链接),父页面将保持其先前位置。 因此,我使用了scrollTop返回页面顶部。

一切正常,但是jquery仅在iframe完全加载(包括图像在内)时才执行此操作,因此效果不佳...

在iframe页面完全加载之前,如何滚动top(父页面)?

父页面正文代码:

<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
    $('iframe').load(function(){
         $(window).scrollTop(0);
    });
});</script>
<iframe frameborder="0" height="1000" id="iframe" src="http://mysite.com" width="800"></iframe>

谢谢!

也许?

$('iframe').ready(function(){
     $(window).scrollTop(0);
});

我认为您可以这样做:

<script type="text/javascript">

jQuery(document).ready(function() {

         $(window).scrollTop(0);
    });
</script>

如果我阅读正确,这应该可以工作:

$('.mylink').click(function(){
 $('html, body').scrollTop(0);
 $('#iframe1').attr('src', 'http://some-other-url');
 window.frames["iframe1"].location.reload();
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM