0

我正在尝试为 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为 nullF.router且不存在于对象上。

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

4

1 回答 1

3

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

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

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

这使得 FancyBox 按预期工作。

于 2012-11-20T16:49:32.793 回答