[英]How to call a function only after page has finished loading and after another function has been called
So I'm using http://kenwheeler.github.io/slick/ and http://instafeedjs.com/ and I'm trying to make a carousel slider based on an instagram feed, the problem I'm running into is that since the content in #instafeed
is dynamically loaded, it keeps returning back undefined in my javascript code because it hasn't been injected into the dom yet. 所以我正在使用http://kenwheeler.github.io/slick/和http://instafeedjs.com/,并且我正在尝试根据instagram feed制作轮播滑块,我遇到的问题是由于#instafeed
的内容是动态加载的,因此它一直返回未定义的javascript代码,因为尚未将其注入dom。 How would I load the code after the function userFeed.run()
has been called and the instagram photos have been injected? 在调用函数userFeed.run()
并注入instagram照片后,如何加载代码?
$(window).bind("load", function() {
var userFeed = new Instafeed({
get: 'user',
userId: 434846375,
accessToken: '#############################',
limit: 5,
template: '<div style="display: inline-block;"><img src="{{image}}" /></div>'
});
// userFeed.run();
$.when(userFeed.run()).done(function()
{
$('.your-class').slick({
arrows:true
});
var array = $( "#instafeed" ).toArray();
for(i = 0; i < 5; ++i)
{
alert(array[i]);
//$('.your-class').slickAdd(array[i]);
}
});
});
Unfortunately it appears that userFeed.run()
will just return true immediately, and you would need it to return a Deferred/Promise to work with $.when
. 不幸的是,似乎userFeed.run()
会立即返回true,并且您需要它来返回Deferred / Promise以便与$.when
。
You can howerver add an after
callback to the Instafeed initialization that should do what you want: 但是,您可以向Instafeed初始化添加after
回调,该回调应执行您想要的操作:
var userFeed = new Instafeed({
get: 'user',
userId: 434846375,
accessToken: '#############################',
limit: 5,
template: '<div style="display: inline-block;"><img src="{{image}}" /></div>',
after: function() {
// Images added to DOM, do stuff here
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.