question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Popup inside iframe, avoid scroll of outer page

See original GitHub issue

This is my situation:

  • the html page contains an iframe
  • inside the iframe there are some images, and the popup are plugged on these images
  • the iframe has an high height, le’ts say 1000px, without a scroll (it occupies the entire page). Boefore the iframe there is other 1000px of content

The problem is that if I click on an image inside the iframe, and the property css ‘top’ of the iframe isn’t 0 (e.g. the iframe starts in the middle of visible page, it doesn’t start from the top of visible page), the page containing the iframe scrolls down , such that the ‘top’ css property of the iframe becomes 0.

The code for putting the popup on is:

$('.image-popup').magnificPopup({
                                    type: 'image',
                                    closeOnContentClick: true,
                                    mainClass: 'mfp-img-mobile',
                                    image: {
                                        verticalFit: true
                                    },
                                    callbacks: {
                                        open: function() {
                                            var magnificPopup = $.magnificPopup.instance;

                                            var iframe = $(".iframe", parent.document.body).first();
                                            var iframeTop = iframe.offset().top
                                            var scrollTop = $(parent.document.body).scrollTop()
                                            var mytop = (scrollTop + 200) - iframeTop

                                            var el
                                            el = magnificPopup.content
                                            el.css('position', 'fixed')
                                            el.css('top', mytop)
                                        },
                                        close: function() {
                                            // Will fire when popup is closed
                                        },
                                        elementParse: function(item) {
                                            item.el.css('width', 100)
                                         }
                                    }

                                });
                            })

I want to avoid that the outer page scrolls down.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
davidcraigmylecommented, Nov 7, 2016

fixedContentPos: true

0reactions
tukvilliecommented, Jul 6, 2020

Changing Both from auto to true worked for me. Thanks

fixedContentPos: “true”, fixedBgPos: “true”,

Read more comments on GitHub >

github_iconTop Results From Across the Web

Iframe without border and scroll in popup - Stack Overflow
Here is the code I am using. I have used seamless property of HTML5 but that works only with chrome browser. And one...
Read more >
Prevent Page Scrolling When a Modal is Open | CSS-Tricks
Unfortunately overscroll-behavior: contain does not prevent the scrolling when the content is less or equal to the parent(as in, no overflow).
Read more >
How to prevent Body from scrolling when a modal is opened ...
Approach: A simple solution to this problem is to set the value of the “overflow” property of the body element to “hidden” whenever...
Read more >
Overflowing content - Learn web development | MDN
Using overflow: scroll , browsers with visible scrollbars will always display them—even if there is not enough content to overflow. This offers ...
Read more >
Using CSS Overscroll-Behavior To Prevent Scrolling Of Parent ...
If you have an overflow: auto element, the user can scroll the content contained within that element. However, when the user hits the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found