Magnific-popup: Disable popup from a drag event

Created on 10 Feb 2015  路  5Comments  路  Source: dimsemenov/Magnific-Popup

I have images in a carousel plugin (slick), and the plugin supports drag events to scroll through the images. However, click events still are triggered on drag events.

Is there a way to prevent popups from opening on a link when a click event occurs after a drag event?

Most helpful comment

I ran into the same problem, but found a solution using slicks events and setting a flag. Maybe this can help you:

// Flag to disable opening while dragging - "true" means MFP is allowed to open up.
var mfpOpen = true;  

// Return the flag inside the disableOn option
$('.galery-img-link').magnificPopup({
  type: 'image',
  disableOn: function() {
    return mfpOpen;
  }
});  

// Set the flag using slick鈥檚 events  
$('.slick-slider').on('beforeChange', function(){
  mfpOpen = false;    
});  

$('.slick-slider').on('afterChange', function(){    
  mfpOpen = true;        
});    

All 5 comments

I ran into the same problem, but found a solution using slicks events and setting a flag. Maybe this can help you:

// Flag to disable opening while dragging - "true" means MFP is allowed to open up.
var mfpOpen = true;  

// Return the flag inside the disableOn option
$('.galery-img-link').magnificPopup({
  type: 'image',
  disableOn: function() {
    return mfpOpen;
  }
});  

// Set the flag using slick鈥檚 events  
$('.slick-slider').on('beforeChange', function(){
  mfpOpen = false;    
});  

$('.slick-slider').on('afterChange', function(){    
  mfpOpen = true;        
});    

Thank you! this really helps!

how did you guys deal with slick cloning the elements in the carousel as magnific popup is evaluating all the anchors from the clones as well as the non clones so I get image double ups in the gallery

@owlyowl I haven't noticed any double elements like you're spoke off. Maybe this is a separate issue.

@owlyowl the easiest way would be to add infinite: false to your slider
$('.slick-slider').slick({ infinite: false, ..other options });

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Madeirense picture Madeirense  路  6Comments

wojto picture wojto  路  4Comments

jglesner picture jglesner  路  3Comments

vol4ikman picture vol4ikman  路  4Comments

tillilab picture tillilab  路  4Comments