调用.open()时未显示Fancybox 2

时间:2012-11-13 20:17:46

标签: fancybox-2

我正在尝试为Fancybox安装一个Knockout绑定(虽然我不认为这里涉及太多)。我根据示例中的代码调用Fancybox:http://jsfiddle.net/STgGM/

$.fancybox.open([{
                    href: value.image(),
                    title: value.title()
                }], {
                    padding: 0
                });

传入的对象如下:

{href: "http://example.com/imageurl", title: "Image Title"} 

单步执行fancybox代码,它试图在脚本的第855行周围显示图像:

if (!type) {
    F.coming = null;

    //If we can not determine content type then drop silently or display next/prev item if looping through gallery
    if (F.current && F.router && F.router !== 'jumpto') {
        F.current.index = index;

        return F[ F.router ]( F.direction );
    }

    return false;
}

我现在还不完全确定它在寻找什么。 F.current为空,对象上不存在F.router

因此,简而言之,我试图通过链接点击触发Fancybox,而无需修改我的标记,或者在特定元素上调用.fancybox()。这似乎是可能的,但它似乎对我不起作用。

1 个答案:

答案 0 :(得分:3)

在深入挖掘代码后,我终于找到了解决方案。 Fancybox试图通过检查我提供的URL来弄清楚我要告诉它显示的内容类型。由于我的URL没有扩展名,因为它来自使用和ID访问图像的外部服务,而不是完整的文件名,Fancybox不知道我告诉它显示什么,并放弃了。

解决方案,因为我知道内容是什么,是这样的:

$.fancybox.open({
            href: value.image(),
            title: value.title(),
            type: 'image'
        },//other stuff (not relevant to this)

这使FancyBox按预期工作。

相关问题