加载图像后继续功能
Continue function after load image
我是JS的初学者。我有一个函数来延迟加载图像在引导旋转木马。如何在加载图像后继续此功能?
$("#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);
});
等待onload事件:
$("#slider").on("slid.bs.carousel", function()
{
var that = this;
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:
$(nextImage).on("load",function(){
clearTimeout(t);
$("#slider").carousel("pause");
var duration = $(that).find("div.active").attr("data-interval");
t = setTimeout(function() { $("#slider").carousel({interval: 1000}); }, duration-1000);
});
});
相关文章:
- 添加文字和评论功能更新Div
- JavaScript打印功能使日历停止工作
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 如何防止网页加载后自动启动功能
- 除修剪外的其他功能
- 悬停功能触发器
- 使用angularjs向浏览器发送servlet响应(下载功能)
- 删除CKEditor工具栏按钮,但不删除功能
- 异步facebook功能
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- jQuery滚动功能只工作一次
- Graphiti中是否有任何工具提示功能
- 继续功能,直到释放鼠标为止
- GAS - 等到用户输入数据后,功能才会继续
- 加载图像后继续功能
- 即使选择器被移除,Jquery的点击功能也会继续工作
- Ember js:在我的例子中,为什么路由器中的逻辑会继续,即使其中使用的功能还没有完成
- IE问题:禁用linkbutton onclientclick并继续执行onclick功能
- Javascript:等待几帧后再继续功能
- 如何在换页后继续功能