假设我在网页上有一个按钮。只要单击该按钮,就会异步预加载某些内容(可以达到5MB的整个图像文件列表),并在加载完成后添加到网页中。
但是,如果在第一个预加载程序完成之前再次单击该按钮,则停止预加载程序才有意义,然后启动第二个。我怎样才能实现这种强制停止?
顺便说一下,我正在使用Ariel Flesler's jQuery based image preloader。
提前致谢!
答案 0 :(得分:2)
它的werid代码有2个地方保存图像img
变量和$preload.cache
数组。
你可以加上这个
settings.control(function() {
imgs = null;
$preload.cache = [];
});
可以在这一行之后
var imgs = $(Array(settings.threshold+1).join('<img/>'))
.load(handler).error(handler).bind('abort',handler).each(fetch);
您可以将功能传递给中止
var _abort = null;
$('<your button>').click(function() {
if (_abort) {
_abort();
}
$.preload( '#images img', {
placeholder:'placeholder.jpg',
notFound:'notfound.jpg'
control: function(abort) {
_abort = abort;
}
});
});
应该可行,但我不确定是否会这样。