jQuery 无限循环 RSS 元素
我正在使用 jGFeed 从远程服务器检索 RSS 提要。 没什么难的,真的。我遇到的问题是关于提要的显示:我试图循环 rss 的每个检索元素并显示它。然后删除它,并显示下一个。
这是我尝试这样做的方法,但没有成功:
$(document).ready(function() {
function loop(links){
var i = 0;
var arrayLength = links.length;
for (i=0;i<=arrayLength;i++){
$('#rssLink').empty().append(links[i]).fadeIn("slow");
setTimeout(function() {
$('#rssLink').fadeOut("fast");
}, 5000);
}
}
function animate(feeds){
var taille = feeds.length;
var links = [];
for ( var i = 0; i < taille; i++ ){
links[i] = "<a href='"+feeds[i].link+"'>"+feeds[i].title+"</a>";
}
loop(links);
}
$.jGFeed('http://www.wrc.com/services/newsrss.jsp',
function(feeds){
// Check for errors
if(!feeds){
// there was an error
return false;
}
animate(feeds.entries);
}, 50);
});
I'm using the jGFeed to retrieve RSS feed from distant server.
Nothing hard, really. Issue I'm having is about the display of the feed : I'm trying to loop over each retrived element of the rss, and display it. Then remove it , and display the next one.
Here's how i'm trying to do so, without success :
$(document).ready(function() {
function loop(links){
var i = 0;
var arrayLength = links.length;
for (i=0;i<=arrayLength;i++){
$('#rssLink').empty().append(links[i]).fadeIn("slow");
setTimeout(function() {
$('#rssLink').fadeOut("fast");
}, 5000);
}
}
function animate(feeds){
var taille = feeds.length;
var links = [];
for ( var i = 0; i < taille; i++ ){
links[i] = "<a href='"+feeds[i].link+"'>"+feeds[i].title+"</a>";
}
loop(links);
}
$.jGFeed('http://www.wrc.com/services/newsrss.jsp',
function(feeds){
// Check for errors
if(!feeds){
// there was an error
return false;
}
animate(feeds.entries);
}, 50);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您将使用这一行超出数组长度:
您应该在 i << 时继续数组长度。
此外,您的“循环”函数将快速连续添加所有链接,每次都会清除 #rssLink 元素。要缓慢迭代数组,您可以尝试以下操作:
Looks to me like you're going to go one beyond the array length with this line:
You should go while i < arrayLength.
Also, your 'loop' function is going to quickly add all the links in succession, clearing the #rssLink element each time. To iterate the array slowly, you could try something like: