好的,我有一个函数可以获取 vine 推文,然后通过 iFrame 显示视频。这很好用,唯一的问题是我不想一次全部列出,我只想显示一个,然后在完成后显示下一个。这可能很简单,但我一直在看代码很长时间,现在我想不通。请帮忙。
function getTweets() {
var url='http://search.twitter.com/search.json?callback=?&q=givingvine';
$.getJSON(url,function(json){
//setup an array to buffer output
var output = [];
//a for loop will perform faster when setup like this
for (var i = 0, len = json.results.length; i < len; i++) {
//instead of appending each result, add each to the buffer array
output.push('<p>' + '<iframe class="video" src="' + json.results[i].text.substr(json.results[i].text.indexOf("http")) +'" frameborder="0" width="1080" height="800" style="margin:-155px -100px -130px -60px;"></iframe>' + '</p>');
}
//now select the #results element only once and append all the output at once, then slide it into view
$.each(output, function (intIndex, objValue) {
$("#results").html(objValue);
});
});
}
//set an interval to run the getTweets function (30,000 ms is 5 minutes), you can cancel the interval by calling clearInterval(timer);
var timer = setInterval(getTweets, 10000);
clearInterval(timer);
//run the getTweets function on document.ready
getTweets();
});