我是JS的初学者。我有一个功能,在bootstrap轮播中延迟加载图像。如何在加载图像后继续此功能?
$("#slider").on("slid.bs.carousel", function()
{
var nextItem = $("#slider").find("div.active").next(".item");
if(!nextItem.length)
{
nextItem = $(".active.item").siblings(":first");
}
var nextImage = nextItem.find("img");
if(nextImage.hasClass("lazy-load"))
{
var src = nextImage.attr("data-src");
nextImage.removeClass("lazy-load");
nextImage.attr("src", src);
}
//the following code must be executed after nextImage is loaded:
clearTimeout(t);
$("#slider").carousel("pause");
var duration = $(this).find("div.active").attr("data-interval");
t = setTimeout(function() { $("#slider").carousel({interval: 1000}); }, duration-1000);
});
答案 0 :(得分:0)
等待onload事件:
image