admin管理员组文章数量:1315812
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
}
});
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
}
});
Share
Improve this question
asked Aug 5, 2013 at 20:24
BrendanBrendan
19.4k19 gold badges89 silver badges117 bronze badges
1 Answer
Reset to default 8It 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
版权声明:本文标题:javascript - How do I define a gallery of inline content in HTML for use with Magnific-Popup ? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741984882a2408615.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论