jQuery滚动到iframe父级的顶部
我有一个带有反馈表单的iFrame。 用户单击提交后,我希望使用父窗口滚动到顶部。 我知道我可以滚动到页面顶部:
$('html, body').animate({scrollTop:0}, 'slow');
但是,这只会滚动iframe的内容,而不是父页面。 有什么建议?
尝试一下这个:
window.parent.$("body").animate({scrollTop:0}, 'slow');
这似乎也可以解决问题:
$('html, body', window.parent.document).animate({scrollTop:0}, 'slow');
$
的第二个参数是要搜索的上下文。
在Iframe页面中。
window.parent.ScrollToTop(); // Scroll to top function
在parrent页面上:
window.ScrollToTop = function(){ $('html,body', window.document).animate({ scrollTop: '0px' }, 'fast'); };
在iframe的html页面的正文中
它尽可能简单!