本文介绍了滚动时使用ajax加载内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 jQuery 工具插件作为图像滑块(图像在这里),但由于图像数量很大,我需要一次加载很少的图像.由于它是 javascript 编码的,据我所知,我无法获得滚动位置.我想在最后一张图片出现后立即加载它们或类似的东西.我不知道我放在哪里,事件监听器也没有任何东西.
I'm using jQuery Tools Plugin as image slider (image here), but due to large amount of images I need to load them few at a time. Since it's javascript coded, I can't have the scroll position as far as I know. I want to load them as soon as the last image shows up or something like that. I have no idea where I put and event listener neither anything.
这是我的代码 http://jsfiddle.net/PxGTJ/
请给我一些光!
推荐答案
我只需要使用 jQuery Tools 的 API,scrollable()
方法中的 onSeek
参数.
I just had to use jQuery Tools' API, the onSeek
parameter within the scrollable()
method.
原来是这样
$(".scrollable").scrollable({
vertical: true,
onSeek: function() {
row = this.getIndex();
// Check if it's worth to load more content
if(row%4 == 0 && row != 0) {
var id = this.getItems().find('img').filter(':last').attr('id');
id = parseInt(id);
$.get('galeria.items.php?id='+id, null, function(html) {
$('.items').append(html);
});
}
}
});
这篇关于滚动时使用ajax加载内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!