Popup inside iframe, avoid scroll of outer page
See original GitHub issueThis 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:
- Created 10 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fixedContentPos: true
Changing Both from auto to true worked for me. Thanks
fixedContentPos: “true”, fixedBgPos: “true”,