是否可以准确地使用$.fancybox.open
并只为该函数提供 1 个参数,其中将是图像列表和所有需要的选项。
我的意思是这样的:
$.fancybox.open(mygallery());
我的问题是我不想这样使用它:
$.fancybox.open(mygallery(), options);
选项可以与 1 个参数中的图像列表一起使用吗?
You can set all your gallery elements with different API options in a single variable that you can use as parameter within the $.fancybox.open()
method like :
var param = [{
// fancybox options first element
href: "http://fancyapps.com/fancybox/demo/1_b.jpg",
title: "the title",
padding: 0,
margin: [20, 100, 0, 0],
afterShow: function () {
alert("hello") // example of callback function
}
}, {
// fancybox options second element, etc.
href: "http://fancyapps.com/fancybox/demo/2_b.jpg",
title: "the second title",
padding: 10,
afterShow: function () {
alert("the second") // example of callback function
}
}];
$.fancybox.open(param);
See JSFIDDLE