我目前正在使用Aylien News API(https://newsapi.aylien.com/docs/introduction)和Swiper.js幻灯片(http://idangero.us/swiper/#.WZwPaZOGPao)来创建滑动新闻自动收录器。
我遇到的问题是滑块一个接一个地遍历所有div,但是当新内容进入时,滑块开始在div之间跳转而不是通过它们运行。
我的HTML由3个div组成 - #aylien-output,然后是#results,然后#story全部嵌套在一起。每个新闻帖都包含在自己的#story div中,该div会在数据被拉入时创建。
目前,我的Javascript看起来像这样:
$(document).ready(function(){
var divListChildren = '';
$('results').find('a').each(function(index,ele){
divListChildren += ele.innerHTML + '';
})
console.log(divListChildren);
})
function getData() {
fetch('http://localhost:3010/test', myInit).then(function(response) {
return response.json();
}).then(function(res) {
fetchedStories = res.stories.filter(
function(story) {
return ! fetchedStories.find (function(fetchedStory) {
return story['id'] === fetchedStory['id'];
});
}
).concat(fetchedStories);
res.stories.map(makeStory);
runSlider();
});
}
getData();
const timeOutTime = 60000;
setTimeout(function doSomething() {
console.log('getting new stuff!');
getData();
setTimeout(doSomething, timeOutTime);
}, timeOu
tTime);
有没有任何方法可以在没有滑块跳过的情况下实时刷新内容?或者等待滑块循环遍历最后一个div并等待新内容,直到它再次从头开始?
我不想每次刷新页面,因为我希望它看起来无缝。
谢谢!