我正在使用一个加载器,它将等待angularJs指令完成并完成。反之亦然,如果我的指令先完成,则img加载器必须紧随其后才显示我的页面。之后,指令将完成执行,我将使用角度$ timeout广播dom事件
$timeout(function() {
var DirectivesEnded = new Event('DirectivesEnded');
document.dispatchEvent(DirectivesEnded);
}, 5000);
我也使用jquery插件等待所有img加载。
$images = $("img");
imagesLoaded($images).on('done', function (instance, image) {
});
在两个事件都触发之后,我想执行这些代码行以使加载程序的html层消失。
$(".lazy-load").animate({
'opacity': 0
}, 300, "linear", function () {
setTimeout(function () {
$(".lazy-load").hide();
}, 10);
});
这些事件和功能都分别运行。但是我的目的是将两者结合起来。任何人都有一个想法如何做到这一点?
如果我很好地理解了您的问题,这应该可以完成工作:
var check_sum = 0;
$timeout(function() {
var DirectivesEnded = new Event('DirectivesEnded');
document.dispatchEvent(DirectivesEnded);
check_sum++;
finished();
}, 5000);
$images = $("img");
imagesLoaded($images).on('done', function (instance, image) {
check_sum++;
finished();
});
function finished() {
if(check_sum==2) check_sum=0;
else return;
$(".lazy-load").animate({
'opacity': 0
}, 300, "linear", function () {
setTimeout(function () {
$(".lazy-load").hide();
}, 10);
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句