我使用owl-carousel jquery插件和instafeedjs。当instafeedjs运行时,owl-carousel看不到子元素。当我尝试使用length函数查找元素(类为instaImg)时,它返回0。但我确定它有27个元素。如何查找元素?我认为问题出在页面加载后创建元素,但我尝试了setTimeOut(),它仍然返回0。
有没有人有什么建议或者简单的插件?
代码:
var feed = new Instafeed({
get: 'tagged',
tagName: 'awsome',
clientId: 'xxxxxxxxxxxx',
template: '<div class="instaImg"><a href="{{link}}"><img src="{{image}}" /></a></div>',
resolution : 'thumbnail'
});
feed.run();
$(document).ready(function(e) {
var count =$('.instaImg').length;
console.log(count);
});<div id="instafeed" class="instaThings" style="width:9999999px;"></div><script src="https://raw.githubusercontent.com/stevenschobert/instafeed.js/master/instafeed.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
发布于 2015-09-11 21:24:40
把你的Instafeed部件放在文档就绪处理程序中。
您在加载之前调用了instafeed。
这就是为什么instafeed尝试这样做的原因:
document.getElementById('instafeed')它以失败告终。
所以这里有一个解决方案:
$(function(e) {
var feed = new Instafeed({
target: 'instafeed',
get: 'tagged',
tagName: 'awsome',
clientId: 'bf6f84fcd7d643daa915f14a5fef657e',
template: '<div class="instaImg"><a href="{{link}}"><img src="{{image}}" /></a></div>',
resolution : 'thumbnail'
});
feed.run();
var count =$('.instaImg').length;
console.log(count);
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://raw.githubusercontent.com/stevenschobert/instafeed.js/master/instafeed.min.js"></script>
<div id="instafeed" class="instaThings" style="width:9999999px;"></div>
https://stackoverflow.com/questions/32523493
复制相似问题