I am using Magnific Popup plugin for displaying image in lightbox.When I click on the image in Chrome, the browser scrolls on the top, after that the menu is not clickable.
$('.img-item').magnificPopup({
type: 'image',
gallery:{
enabled:true
}
});
We can close magnific popup in various ways We can add a button within the popup and assign a function on click event like $('#close-button-verify'). click(function(){ //This will close the most recently popped dialog //This method specially works for auto popped dialogs i.e. //Popup you opened using $. magnificPopup.
Magnific Popup is a fast, light, mobile-friendly and responsive lightbox and modal dialog jQuery plugin. It can be used to open inline HTML, ajax loaded content, image, form, iframe (YouTube video, Vimeo, Google Maps), and photo gallery. It has added animation effects using CSS3 transitions.
All you need to do to use Magnific Popup on a link is to add specific css class to 'a' tag. CSS class names can be configured on settings page. For images you can use alt attribute to add captions. This plugin is only basic version and does not support all features of Magnific Popup yet.
Alright folks, I guess I found the solution.
I trimmed off my full script yet fixedContentPos: false
, adding noscroll
to body element on "open" and remove it on "close" is important :
$('.open-link').magnificPopup({
type: 'image',
closeOnBgClick: true,
fixedContentPos: false,
callbacks: {
open: function() {
jQuery('body').addClass('noscroll');
},
close: function() {
jQuery('body').removeClass('noscroll');
}
}
});
Finally, create a CSS rule for noscroll as :
body.noscroll {
overflow-y: hidden!important;
}
fixedContentPos:false
prevents using fixed position for body and keeps the scrollbar on the same position. However, it doesn't prevent scroll and user is still able to scroll up / down. Using overlow-y:hidden
hides scrollbar and disables mousewheel.
Magnific has an option fixedContentPos
. This is set to 'auto' by default, causing it to fix content to the top. Setting fixedContentPos: false
should force magnific to use the absolute position based on current scroll.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With