dimsemenov / Magnific-Popup

Light and responsive lightbox script with focus on performance.
http://dimsemenov.com/plugins/magnific-popup/
MIT License
11.39k stars 3.48k forks source link

Vertical centering of modal within very tall iframe #728

Open jaysonhunter opened 9 years ago

jaysonhunter commented 9 years ago

I have a page with an iframe and the height of this iframe is dynamically set to the height of its content, around 3000px. The modal popup styling and logic is part of the iframe HTML page, not the parent page.

When the modal displays, it's positioned in the center of the tall iframe way down the page out of view.

How do I get it to position properly in the center of the window and not the entire iframe height?

pomartel commented 9 years ago

Did you find a way? I have the same problem.

jaysonhunter commented 9 years ago

Hello Pierre. Yes I did manage to get this working to a degree, although it's not perfect. I'll post a URL to the example in a few days.

pomartel commented 9 years ago

I ended up doing this (coffeescript) :

$('.pictures-gallery').magnificPopup
  callbacks:
    open: resizeThumbnailViewer
    imageLoadComplete: resizeThumbnailViewer

resizeThumbnailViewer = ->
  $('.mfp-wrap').css({top: viewport.scrollTop(), height: viewport.height()})
  $('.mfp-img').css({'max-height': viewport.height()})

So basically, whenever the popup opens or a new image is loaded, I play with some css properties of mfp-wrap and mfp-img to center it properly inside the iframe. Works perfectly!

jaysonhunter commented 9 years ago

Hi Pierre. I used a similar approach to you with this code:

$.magnificPopup.open({ fixedContentPos: true,

            callbacks: {
                beforeOpen: function () {
                     windowHeight = $(window.parent).height();
                     iFrameScrollPos = $(window.parent.document).scrollTop();
            },
                open: function () {
                   $('.mfp-wrap').css({'position': 'absolute', 'top': iFrameScrollPos, 'left': 0, 'height':      windowHeight});
            }

})

outsight commented 7 years ago

Thank you Jayson! I was having the same problem today and your solution saved me hours of frustration.