将卡片样式应用于单个Google Feed API结果
Applying Card style to individual Google Feed API result
我使用的是Google Feed API
我的HTML头包含这个:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
var feed = new google.feeds.Feed("http://feeds.ign.com/ign/game-reviews");
feed.setNumEntries(20);
feed.load(function (result) {
if (!result.error) {
var container = document.getElementById("feed0");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var card = document.getElementById("card");
card.appendChild(document.createTextNode(entry.title));
card.appendChild(document.createTextNode(entry.contentSnippet));
card.appendChild(document.createTextNode(entry.link));
container.appendChild(card);
}
}
});
}
google.setOnLoadCallback(initialize);
</script>
然后在body中我有:
<article id="feed0">
<div id="card"></div>
</article>
我试图在css中将每个提要条目单独设置为一个"卡片",最终目标是创建看起来像Google+提要的东西:
#feed0, #feed1{
display:-webkit-box;
-webkit-box-orient:vertical;
-webkit-box-flex:1;
}
#card{
border:1px solid gainsboro;
background-color:white;
display:-webkit-box;
-webkit-box-orient:vertical;
-webkit-box-flex:1;
font:10px Tahoma;
margin:8px;
padding:15px;
}
我得到的不是让样式应用于每个提要结果,而是一个样式正确的框,但它包含了里面的所有提要。
如何将样式应用于每个单独的提要结果,而不是所有的提要结果?
基本上你选择了一个单一的DOM元素,然后试图追加它,但它是一个单一的元素。
这是我的例子,我使用jquery和Array。forEach简化:http://cdpn.io/HLJqd
不需要jQuery,它只是更快。
相关文章:
- JavaScript回调函数和Google Feed API
- Google Feed API-返回媒体:缩略图
- Consume Google Feed API with Phantomjs
- 如何在使用Google Feed API时获取帖子ID
- Google Feed API跳过文章
- Google Feed API'发布日期'错误的一天
- 使用AJAX加载RSS提要:Google feed API的替代方案
- Google Feed API -从RSS提要加载缓存结果
- Google Feed API日期到HTML5日期时间
- 如何在页面加载中访问由Google feed API返回的值
- Google Feed API是否支持从RSS提要返回图像?
- Google Feed API: more than one feed
- 使用Google feed API阅读Twitter RSS
- Google Feed API -从Feed加载图片失败
- 从Google Feed API同时绘制多个提要
- 将卡片样式应用于单个Google Feed API结果
- setTimeout problem with Google Feed API
- Google Feed API with jQuery`s AJAX
- Google Feed API有域名/URL限制吗?
- Angular $http and Google Feed API