I'm trying to create a page with a few galleries using the Magnific-Popup jQuery plug-in. I different sections contained in div
s with separate ids and a .gallery
class containing the images.
<div id="content_1">
<p>Some content</p>
<div class="gallery">
<a href="img/pic_1"><img src="img/pic_1.jpg"></a>
<a href="img/pic_2"><img src="img/pic_2.jpg"></a>
</div>
</div>
<div id="content_2">
<p>More content</p>
<div class="gallery">
<a href="img/pic_3"><img src="img/pic_3.jpg"></a>
<a href="img/pic_4"><img src="img/pic_4.jpg"></a>
</div>
</div>
To get the galleries to be separate in the popup I initialized the script multiple times for each content section. When I do this, however, after the first content section, there are more images in the gallery popup (twice as much to be exact) than I linked to. I'm new to javascript, so I'm not sure if I'm just missing something obvious.
1) Add MP files to your theme's directory Create the directory magnific-popup in your theme's directory. Download the MP CSS and JS files from GitHub and put both in the magnific-popup directory: jquery. magnific-popup.
This can be done by using the Google-hosted version of jQuery or downloading and using the distribution files. Include CSS: Add the magnific-popup. css file from the dist folder of Magnific.
From the documentation:
To have multiple galleries on a page, you need to create a new instance of Magnific Popup for each seperate gallery. For example
<div class="gallery"> <a href="path-to-image.jpg">Open image 1 (gallery #1)</a> <a href="path-to-image.jpg">Open image 2 (gallery #1)</a> </div> <div class="gallery"> <a href="path-to-image.jpg">Open image 1 (gallery #2)</a> <a href="path-to-image.jpg">Open image 2 (gallery #2)</a> <a href="http://vimeo.com/123123" class="mfp-iframe">Open video (gallery #2). Class mfp-iframe forces "iframe" content type on this item.</a> </div>
Javascript
$('.gallery').each(function() { // the containers for all your galleries $(this).magnificPopup({ delegate: 'a', // the selector for gallery item type: 'image', gallery: { enabled:true } }); });
Hope that helps!
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