[英]Script loaded with HeadJS runs only on second click
HeadJS加載的腳本僅在第二次單擊時運行。 如何在首次點擊時獲得Aviary啟動器?
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
事件:
var featherEditor = new Aviary.Feather({
apiKey: 12345,
apiVersion: 3,
onLoad: function() {
featherEditor.launch({
image: $id,
url: $src
});
}
});
回答邁克布里奇(Mikebridge)在第二次沒有打開的情況下:
某些黑暗的原因阻止了羽毛被多次實例化。 使用window.globalAviaryFeather來保存實例。
function launch(url) {
window.globalAviaryFeather.launch({
image: "imgId",
url: url
})
}
var url = "..."
if (window.globalAviaryFeather) {
launch(url)
} else {
window.globalAviaryFeather = new Aviary.Feather({
...
onLoad: function() {
self.launch(url)
}
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.