如何在fancybox中获取当前图像索引? [英] How to get current image index in fancybox?

查看:100
本文介绍了如何在fancybox中获取当前图像索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在fancybox画廊中获取当前图像索引.文档中有一个pos方法,但它只是setter方法,不适用于getter.

I am trying to get current image index in fancybox gallery. There is a pos method in documentation but it is just setter method and not working for getter.

$.fancybox.pos(3) // works fine
var index = $.fancybox.pos() // does not work . It returns undefined. 

我知道pos被设计为设置方法,但我需要知道 fancybox画廊中的当前图像索引.
我怎么知道当前的图像索引?

I understand that pos is designed as setter method but i need to know current image index in fancybox gallery.
How can i know current image index ?

推荐答案

类似以下内容应该可以:

Something like the following should do just fine:

var src = $('#fancybox-img').attr('src'); // Looks for the *fancyboxed* image
var idx = $('a[href="'+src+'"]').index(); // Gets the index of the thumbnail

如果您使用某些自定义DOM层次结构,则您可能必须采用此解决方案.

You may have to adapt this solution if you use some custom DOM hierarchy.

这篇关于如何在fancybox中获取当前图像索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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