Fancybox v2 override/format title

隐身守侯 提交于 2019-12-11 01:35:14

问题


How can i override the Title in the new version of fancy box?

$(document).ready(function() {
    $(".photogalleryLightbox li a").fancybox({
        helpers:{ 
                    title: {
                        type: 'inside',
                        beforeShow: function(opts)
                                    {
                                        console.log('beforeShow title helper');
                                    },
                        },
                    buttons : {}
                },
        beforeShow: function()
        {
            console.log('beforeShow');
            // var obj = $(currentArray[currentIndex]); // from prev. version
            // if (obj.next().length) return obj.next().html(); // from prev. version
        }
    });
});

I tried this but don't know how to get the variables as index.


回答1:


You can use callbacks to update title, example:

$(".photogalleryLightbox li a").fancybox({
        beforeLoad : function() {
            this.title = 'My Custom Title';
        },
        helpers: { 
            title: {
                type: 'inside',
                beforeShow: function(opts) {
                    console.log('beforeShow title helper');
                },
            },
            buttons : {}
        },
        beforeShow: function() {
            console.log('beforeShow');
            // var obj = $(currentArray[currentIndex]); // from prev. version
            // if (obj.next().length) return obj.next().html(); // from prev. version
        }
    });



回答2:


I have added image-numbers to the title like this:

beforeShow : function() {
  this.title = '<span class="imgNo">Bild ' + (this.index + 1) + ' von ' + this.group.length + '</span>' + (this.title ? '' + this.title + '' : '');
}

This works great but the calculation of sizes and offsets of div.fancybox-wrap goes wrong: With my image-numbers every image has a title in the lightbox, but not all of them get a 'real' title from the thumbnails title-tag. But the sizes are calculated only with those 'real' titles.

Adding the image-numbers in beforeLoad() works too but with the same problem.

Has anybody an idea how to fix the calculation? I haven't found it in the fancybox-code yet, so I could fix it there but I would prefer to do it in a callback function and not by changing the source code.



来源:https://stackoverflow.com/questions/8225416/fancybox-v2-override-format-title

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!