jQuery滚动到iframe父级的顶部

时间:2010-09-27 15:19:14

标签: jquery scroll

我有一个带有反馈表单的iFrame。用户单击提交后,我希望使用父窗口滚动到顶部。我知道我可以滚动到页面顶部:

$('html, body').animate({scrollTop:0}, 'slow');

但是,这只会滚动iframe的内容,而不是父页面。 有什么建议吗?

5 个答案:

答案 0 :(得分:32)

试试这个:

window.parent.$("body").animate({scrollTop:0}, 'slow');

答案 1 :(得分:11)

这似乎也可以解决问题:

$('html, body', window.parent.document).animate({scrollTop:0}, 'slow');

second parameter$是要搜索的上下文。

答案 2 :(得分:8)

<script>
    jQuery(document).ready(function($) {
        FB.Canvas.scrollTo(0,0);
        FB.Canvas.setSize({width: 760, height:$('body').height()+20});
    });

    function scrollTo(x,y) {
        $("body").append('<iframe id="scrollTop" style="border:none;width:1px;height:1px;position:absolute;top:-10000px;left:-100px;" src="http://static.ak.facebook.com/xd_receiver_v0.4.php?r=1#{%22id%22%3A0%2C%22sc%22%3Anull%2C%22sf%22%3A%22%22%2C%22sr%22%3A2%2C%22h%22%3A%22iframeOuterServer%22%2C%22sid%22%3A%220.957%22%2C%22t%22%3A0}[0%2C%22iframeInnerClient%22%2C%22scrollTo%22%2C{%22x%22%3A'+x+'%2C%22y%22%3A'+y+'}%2Cfalse]" onload="$(\'#scrollTop\').remove();"></iframe>');
    }
</script>

答案 3 :(得分:1)

在Iframe页面中。

window.parent.ScrollToTop(); // Scroll to top function

在父页面上:

window.ScrollToTop = function(){
  $('html,body', window.document).animate({
    scrollTop: '0px'
  }, 'fast');
};

答案 4 :(得分:1)

<body onLoad="window.parent.scroll(0,0);">

在iframe的html页面正文中

它尽可能简单!

相关问题