Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magnific Popup - Browser scrolls on the top on image click

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
    }   
});
like image 522
user3351236 Avatar asked Mar 12 '14 13:03

user3351236


People also ask

How do I get rid of Magnific popup?

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.

What is Magnific popup CSS?

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.

How do I use Magnific popup in wordpress?

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.


2 Answers

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.

like image 75
Mertafor Avatar answered Oct 12 '22 23:10

Mertafor


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.

like image 23
SeeDoubleYou Avatar answered Oct 12 '22 23:10

SeeDoubleYou