How to get scrollTop of an iframe

后端 未结 10 1737
一生所求
一生所求 2020-12-03 03:33

jQuery\'s scrollTop returns null when window is an iframe. Has anyone been able to figure out how to get scrollTop of an iframe?

more info:

my script is runn

10条回答
  •  青春惊慌失措
    2020-12-03 03:56

    I know I'm late to the game here, but I was trying to figure this out for a long list on mobile. scrollTop() wasn't working for me due to cross-domain conflicts(and I didn't have access to parent window), but changing the height did:

    $('#someClickableElementInIFrame').on('click', function(e){
          $("html body").animate({
          'height' : "0"
        }, {
            complete: function(){
              $("html body").css({
                'height' : "auto"
                })
              }
          })
    });
    

提交回复
热议问题