[英]Fancybox Internet Explorer issue
I'm working on a small project and I need to implement Fancybox with MANUAL CALL, meaning I supply the list of images with a JSON list. 我正在做一个小项目,我需要使用MANUAL CALL来实现Fancybox,这意味着我为图像列表提供了JSON列表。 (not sure if this is the correct name of the list)
(不确定这是否是列表的正确名称)
The code looks like: 代码如下:
$("#big_img a").click(function(e) {
e.preventDefault();
jsonObj = [];
var act_index;
$(".gal_thumb").each(function(index) {
var title = $(this).attr('alt');
var href = $(this).attr('data-image');
if(href == $("#img_01").attr('src')) {
act_index = index;
}
item = {}
item ["title"] = title;
item ["href"] = href;
jsonObj.push(item);
});
$.fancybox(
jsonObj,
{
'index': act_index
}
);
});
EDIT 编辑
I paste the HTML as well, which is the following: 我也粘贴了HTML,如下所示:
<div id="big_img">
<a href="#">
<img id="prod_img_magnify" src="..." alt="" />
<img id="img_01" src="..." data-image="..." alt="" />
</a>
</div>
<div id="prod_thumbs">
<a href="#">
<img class="gal_thumb" src="..." data-image="..." alt="" />
</a>
<a href="#">
<img class="gal_thumb" src="..." data-image="..." alt="" />
</a>
</div>
However it works fine on Mozilla and Chrome, it fails in IE even on my Lumia 520. 但是,它在Mozilla和Chrome上运行良好,即使在我的Lumia 520上,在IE中也无法运行。
Can anyone have a input on what should I change to solve this IE problem? 任何人都可以提出解决该IE问题的建议吗? Many thanks!
非常感谢!
EDIT #2 编辑#2
Based upon the documentation found on the Fancybox Docs page, it says that you can pass the list of images and their respective title to fancybox like this: 根据在“ Fancybox文档”页面上找到的文档,它说您可以将图像列表及其各自的标题传递给fancybox,如下所示:
$.fancybox([{
href: 'img1.jpg',
title: 'Title'
}, {
href: 'img2.jpg',
title: 'Title'
}]);
If I pasted it manually in IE it worked. 如果我手动将其粘贴到IE中,它将起作用。 As I replaced manual list with jsonObj, it didn't work in IE.
当我用jsonObj替换手动列表时,它在IE中不起作用。
Question : is: this way I construct the JSON object correct and parseable by all browsers? 问题:是:这样,我构造的JSON对象可以被所有浏览器正确和解析吗?
Is this method correct? 这种方法正确吗?
item = {}
item ["title"] = title;
item ["href"] = href;
jsonObj.push(item);
Is this method correct? 这种方法正确吗?
item = {}
item ["title"] = title;
item ["href"] = href;
jsonObj.push(item);
No, it's not. 不,这不对。 To correctly build your variable items from data in your html and push them into the array use this format :
要从html中的数据正确构建变量项并将其推入数组,请使用以下格式:
var jsonObj = [];
jQuery(document).ready(function ($) {
$(".gal_thumb").each(function (i) {
var item = {
href: $(this).data("image"),
title: this.alt
};
jsonObj.push(item);
}); // each
$.fancybox(jsonObj, {
// API options
index: 1 // the second image
});
}); // ready
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.