jQuery scroll to top of iframe parent

2019-03-14 10:49发布

I have an iFrame with a feedback form in it. After the user clicks submit, I want use parent window to scroll to the top. I know I can scroll to the top of a page with:

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

However, this will only scroll the contents of the iframe, not the parent page. Any suggestions?

标签: jquery scroll
5条回答
叼着烟拽天下
2楼-- · 2019-03-14 11:14

Give a try for this one :

window.parent.$("body").animate({scrollTop:0}, 'slow');
查看更多
欢心
3楼-- · 2019-03-14 11:23

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

In the body of the iframe's html page

Its as simple as you can do!

查看更多
狗以群分
4楼-- · 2019-03-14 11:30

This seems to do the trick as well:

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

The second parameter to $ is the context to search in.

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-03-14 11:39

Within the Iframe page.

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

On The parrent page:

window.ScrollToTop = function(){
  $('html,body', window.document).animate({
    scrollTop: '0px'
  }, 'fast');
};
查看更多
戒情不戒烟
6楼-- · 2019-03-14 11:40
<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>
查看更多
登录 后发表回答