9

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
    }   
});
sth
  • 222,467
  • 53
  • 283
  • 367
user3351236
  • 2,488
  • 10
  • 29
  • 52

7 Answers7

13

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.

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
Mertafor
  • 374
  • 4
  • 17
7

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.

SeeDoubleYou
  • 1,253
  • 2
  • 15
  • 25
  • 1
    didn't work, neither 'auto', true, false. Also, tried with the fixedBgPos and alignTop properties, but no luck., here is how I did it: http://stackoverflow.com/a/28749311/2615737 – Francisco Corrales Morales Feb 26 '15 at 17:49
4

For me it was the problem with delegate:'a' option. Everywhere it was set, I need to add fixedContentPos: false and this did the trick for me.

Phil
  • 943
  • 2
  • 6
  • 18
2

You need use: preventDefault()

JavaScript:

function attach_magnific_popup(e){
e.preventDefault();
jQuery('a.open-popup-link').magnificPopup({
        type: 'inline',
        //fixedContentPos: true,
        //fixedBgPos: true
    });
}

HTML:

<a href="#pop-up-content"  class="open-popup-link" onclick="attach_magnific_popup(event);">Click here...!</a>
0

Sounds like there's a JS error somewhere or your image is wrapped into an <a href=""></a> tag and it interferes with default behavior.

Serg Chernata
  • 12,280
  • 6
  • 32
  • 50
0

Ok, this was a weird thing. Here is how I fix it:

  1. I removed the .magnificPopup({ code from the onReady, and instead move it to a function.

  2. Then I added the an onlick event to the element which triggers the popup.

I don't know why, but that worked.


Here is the code:

JavaScript

function attach_magnific_popup(){
jQuery('a.open-popup-link').magnificPopup({
        type: 'inline',
        //fixedContentPos: true,
        //fixedBgPos: true
    });
}

HTML:

<a href="#pop-up-content"  class="open-popup-link" onclick="attach_magnific_popup();">Click here...!</a>


<div id="pop-up-content" class="white-popup mfp-hide" >
....Pop up content...
</div>

Note: I did tried with fixedBgPos, fixedContentPos, alignTop properties, but didn't work.

0

Looks like moving the magnificPopup code from $(document).ready() to $(window).load() did it for me. Here is my code:

$(window).load(function() {
  $('.open-popup-link').magnificPopup({
    type:'inline',
    closeBtnInside: true,
    fixedContentPos: false,
    midClick: true
  });
});
Tom
  • 4,257
  • 6
  • 33
  • 49
Will Wong
  • 9
  • 1