admin管理员组文章数量:1279115
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.
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 ?
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.
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 ?
- seems like you could try: ("#children_id").val()); as described here – JMax Commented Aug 31, 2011 at 13:20
5 Answers
Reset to default 4Something 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
You may have to adapt this solution if you use some custom DOM hierarchy.
If you are using FancyBox 2 you can use the index property.
$.fancybox.current.index
You can also write your own method to the Fancybox library (jscript_jquery.fancybox-1.3.4.pack.js):
b.fancybox.getPos=function(){return p};
Then you are able reach the index of actual image by call this:
var actualPosition = $.fancybox.getPos();
i used accepted answer to upgrade for v3.2
var src = $('.fancybox-slide--current .fancybox-image').attr('src');
var idx = $('a[href="'+src+'"]')[0];
i needed to find currently showing slide, i needed it for my custom button (to delete that photo)
Easiest and cleanest way to find the current index image in FancyBox 3 :
var idx = $.fancybox.getInstance().currIndex;
$('[data-fancybox="gallery"]').eq(idx).parents('.image_gallery').toggleClass('selected');
本文标签: javascriptHow to get current image index in fancyboxStack Overflow
版权声明:本文标题:javascript - How to get current image index in fancybox? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741234969a2362830.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论