jQuery scroll to top of iframe parent

前端 未结 5 764
长情又很酷
长情又很酷 2021-02-05 05:48

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:

<
相关标签:
5条回答
  • 2021-02-05 06:24

    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.

    0 讨论(0)
  • 2021-02-05 06:26

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

    In the body of the iframe's html page

    Its as simple as you can do!

    0 讨论(0)
  • 2021-02-05 06:31
    <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>
    
    0 讨论(0)
  • 2021-02-05 06:31

    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');
    };
    
    0 讨论(0)
  • 2021-02-05 06:47

    Give a try for this one :

    window.parent.$("body").animate({scrollTop:0}, 'slow');
    
    0 讨论(0)
提交回复
热议问题