如何通过手动调用html中的图库而不通过jquery选项来打开fancybox? [英] How do I open fancybox via manual call for a gallery in the html not via the jquery options?

查看:134
本文介绍了如何通过手动调用html中的图库而不通过jquery选项来打开fancybox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻我只是在看fancybox v2.

I am just looking at the fancybox v2 at the moment.

我正在尝试通过fancybox加载图库,但需要手动调用.我不希望通过jquery加载图库图像,最好是从html页面加载它们,因为这将被添加到CMS的模板中,而CMS需要让用户将图像添加到图库中,在他们上传的每张新图像上填充.

I am trying to get a gallery to load with fancybox but with manual call. I dont want the gallery images to be loaded in via jquery it would be better to have them load from the html page as this is going to be added to a template for a CMS that needs to let the user add images to a gallery that will populate on every new image they upload.

仅仅是在调用之前在选项中添加调用,还是在图像的标签的href中添加调用?

Is it as simple as just adding a call in the options before it starts or in the href of the a tag for the image?

谢谢, 标记

推荐答案

请确保所有新加载的图像在链接到它们的锚点内共享相同的classrel属性.

Make sure that all new loaded images share the same class and rel attribute within the anchor that links to them

<a href="image01.jpg" class="fancybox" rel="gallery" ...

如果需要,这些html锚点可以位于隐藏的div内部.您可以查看此信息以供参考.

Those html anchors can be inside a hidden div if you want. You can check this post for reference.

然后,将它们绑定到fancybox

Then, bind them to fancybox

$(".fancybox").fancybox();

您说您将使用CMS,因此如果加载的图像的href格式类似于 http://path/to/image/?abc=123(例如,没有图像扩展名) 在脚本中添加type:"image"选项

You said you will be using a CMS so if the href format of your loaded images is something like http://path/to/image/?abc=123 (no image extension for instance) add the type:"image" option to your script

$(".fancybox").fancybox({
 type:"image"
});

如果可见锚点,则单击其中任意一个将启动图库.

If the anchors are visible, clicking on any of them will start the gallery.

另一方面,您可以使用任何其他链接手动"启动图库

On the other hand, you may use any other link to start the gallery "manually"

<a href="javascript:;" id="launcher">open gallery</a>

并添加此脚本:

$("#launcher").on("click", function(){
 $(".fancybox").eq(0).trigger("click");
});

.eq()方法用于从第一个项目开始画廊(尽管可以),否则画廊将从最后一个附加项目开始.另外,.on()方法需要jQuery v1.7 +

the .eq() method is used to start the gallery from the first item (can be any though) otherwise the gallery will start from the last appended item. Also, the .on() method requires jQuery v1.7+

这篇关于如何通过手动调用html中的图库而不通过jquery选项来打开fancybox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆