javascript 华丽的弹出窗口:获取“无法加载图像”并且图像 url 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18412335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Magnific popup: getting "The image could not be loaded" and image url is undefined
提问by clime
I cannot make magnific popup work for some reason getting "The image could not be loaded" all the time. The image url is "undefined".
由于某种原因,我无法使 magnific popup 工作始终得到“无法加载图像”。图片网址是“未定义”。
<div class="album">
<a href="http://lorempixel.com/1024/768/?a=1">
<img src="http://lorempixel.com/168/168/?a=1" />
</a>
<a href="http://lorempixel.com/1024/768/?a=2">
<img src="http://lorempixel.com/168/168/?a=2" />
</a>
<a href="http://lorempixel.com/1024/768/?a=3">
<img src="http://lorempixel.com/168/168/?a=3" />
</a>
</div>
<script>
$(function() {
$('div.album').magnificPopup({ type: 'image' });
});
</script>
回答by Jeroen Ingelbrecht
Changed the code to:
将代码更改为:
$(function() {
$('div.album').magnificPopup({delegate: 'a', type: 'image' });
});
As from http://dimsemenov.com/plugins/magnific-popup/documentation.html#initializing_popup
从http://dimsemenov.com/plugins/magnific-popup/documentation.html#initializing_popup
The problem was you referred to the container instead of the 'a' element which contains the link to the image.
问题是您引用了容器而不是包含图像链接的“a”元素。