【问题标题】:jQuery call synchronouslyjQuery 同步调用
【发布时间】:2011-06-28 17:20:51
【问题描述】:

我正在组合 2 个 jQuery 插件,Fancybox 和 Embedly(如 jQuery oembed)。

在 Fancybox onStart 事件中,我获取链接的 url,调用 oembed 服务并将响应(视频)推回灯箱。

好吧,至少这就是我想要发生的事情 :) 我收到了来自 oembed 提供商的回复,但我认为 onStart 函数在发生这种情况时已经完成。

代码:

$('a').fancybox({
    type: 'html',
    onStart: function(selectedArray, selectedIndex, selectedOpts) {
            var url = selectedArray[selectedIndex].href;
            $.embedly(url, {
                success: function (oembed, dict) {
            selectedOpts.content = oembed.html;
                }
            });
    }
});

看来我需要同步处理调用?

谢谢

【问题讨论】:

    标签: jquery fancybox oembed


    【解决方案1】:

    试试这个

    $('a').each(function(i, a){
                var url = a.href, $a = $(a);
                $.embedly(url, {
                    success: function (oembed, dict) {
                         $a.fancybox({
                         type: 'html',
                         onStart: function(selectedArray, selectedIndex, selectedOpts) {
                            selectedOpts.content = oembed.html;
    
                                   }
                         });
                       }
    
                    }
                });
    });
    

    【讨论】:

    • 不幸的是,这意味着我无法在画廊模式下加载链接集合。这就是为什么我需要在元素数组上调用 fancybox 并覆盖 onstart 中的内容。
    猜你喜欢
    • 2015-09-04
    • 1970-01-01
    • 2011-02-25
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多