Pur*_*tha 4 asp.net-mvc jquery magnific-popup
我有一个场景,我的代码显示图像缩略图动态加载到DOM.单击缩略图后,我想使用maginfic弹出窗口加载完整图像.以下是我的看法:
<div class="Right-Panel-Section popup-gallery">
<h2>Images</h2>
@foreach (var media in @Model.lsContentMedia)
{
<div class=" Float-Left" data-id="@media.MediaId">
<a href="@media.ContentMediaFileName" >
<img src="@media.ContentMediaFileName" style="width:80px;height:80px;margin:5px;" title="@media.Description" class="gallery-item"/>
</a>
</div>
}
</div>
Run Code Online (Sandbox Code Playgroud)
由于我无法直接访问DOM元素,我使用委托来连接Magnific,如下所示:
$("#Fixed-Container").on("click", ".popup-gallery", function (event) {
$('.popup-gallery').magnificPopup({
delegate: 'a',
type: 'image',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
}
});
event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
我已正确包含样式和脚本文件.但是,我最初只能在任何图像上点击两次后查看图像.我希望它始终只需单击即可完成.任何有关这方面的帮助将非常感激.
尝试链接.magnificPopup('open')到弹出初始化.
您的代码应为:
$("#Fixed-Container").on("click", ".popup-gallery", function (event) {
$('.popup-gallery').magnificPopup({
delegate: 'a',
type: 'image',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
}
}).magnificPopup('open');
event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)