Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I define a gallery of inline content in HTML for use with Magnific-Popup ?

I have many galleries on a page which are launched from their respective buttons. I like the idea of defining the markup for the galleries in the page alongside the button and then hiding using the .mfp-hide. However I cannot get the popup to activate when I add the delegate keyword (it does otherwise).

Here is the code I have so far,

HTML

<div id="gallery1" class="mfp-hide">
  <div class="slide">
    ... some content for slide 1 ...
  </div>
  <div class="slide">
    ... some content for slide 2 ...
  </div>
</div>

<p>Blah blah <a href="#gallery1" class="open-gallery-link">view gallery one</a> blah blah ...</p>

Javascript

$('.open-gallery-link').magnificPopup({
  type:'inline',
  delegate:'.slide',
  gallery: {
    enabled: true
  }
});
like image 683
Brendan Avatar asked Aug 05 '13 20:08

Brendan


People also ask

How do I use Magnific popup in HTML?

The Magnific CSS Magnific requires it's own CSS code in order to display things properly. Simply add the magnific-popup. css to your page like a normal CSS document. You should include it after your reset/normalize, but before your own styles.

How do I open Magnific popup on page load?

I was able to get a timed modal working using jquery's setTimeout function, Just wrap . magificpopup in the settimeout function to set a delay. Change the value of 5000 (5 seconds) to whatever value you want. setTimeout will not work on server cause it will depend on internet speed.

What is magnific popup?

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.


1 Answers

It doesn't work this way, delegate is always looking for children of target DOM element (in your case children of element .open-gallery-link).

You may just parse everything via jQuery and open gallery via API:

$('.open-gallery-link').click(function() {

  var items = [];
  $( $(this).attr('href') ).find('.slide').each(function() {
    items.push( {
      src: $(this) 
    } );
  });

  $.magnificPopup.open({
    items:items,
    gallery: {
      enabled: true 
    }
  });
});

http://codepen.io/dimsemenov/pen/zvLny

like image 167
Dmitry Semenov Avatar answered Oct 10 '22 09:10

Dmitry Semenov