HeadJS加载的脚本仅在第二次单击时运行 [英] Script loaded with HeadJS runs only on second click

查看:100
本文介绍了HeadJS加载的脚本仅在第二次单击时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HeadJS加载的脚本仅在第二次单击时运行.如何在首次点击时获得Aviary启动器?

Script loaded with HeadJS runs only on second click. How to get Aviary launcher on first click?

http://jsfiddle.net/ynts/6hgEb/

function aviary(id, src) {
    var $id = id;
    var $src = src;

    head.load(
        "http://feather.aviary.com/js/feather.js",
        function() {

            var featherEditor = new Aviary.Feather({
                apiKey: 12345,
                apiVersion: 3

                // ... ///
            });

            featherEditor.launch({
                image: $id,


                  url: $src
                });
            }
        ); 
}

$(document).on('click', 'img', function(){
    var $img = $(this).attr('src');
    aviary('edit-pic', $img);
}); 

推荐答案

在调用launch函数之前,您需要等待插件初始化.您可以使用onLoad事件:

You need to wait for the plugin to initialize, before calling the launch function. There is onLoad event you can use:

var featherEditor = new Aviary.Feather({
                apiKey: 12345,
                apiVersion: 3,
                onLoad: function() {
                     featherEditor.launch({
                        image: $id,
                        url: $src
                    });
                }                                    
            }); 

这篇关于HeadJS加载的脚本仅在第二次单击时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆