Javascript 在图像元素更改其src后计时函数运行
我正在更改一些图像的src属性。加载新图像后,我想运行一个名为wheelBuilder.rebuildColors()的函数 这段代码在某些浏览器(chrome、safari、ie)上运行良好,但在Mozilla firefox上不起作用 是否有办法将其设置为在加载所有图像后运行该函数Javascript 在图像元素更改其src后计时函数运行,javascript,jquery,Javascript,Jquery,我正在更改一些图像的src属性。加载新图像后,我想运行一个名为wheelBuilder.rebuildColors()的函数 这段代码在某些浏览器(chrome、safari、ie)上运行良好,但在Mozilla firefox上不起作用 是否有办法将其设置为在加载所有图像后运行该函数 谢谢,试试这个。您必须在更改src之前设置该函数 var total = $images.length,loaded=0; function testRebuild() { if (loaded==total
谢谢,试试这个。您必须在更改src之前设置该函数
var total = $images.length,loaded=0;
function testRebuild() {
if (loaded==total) wheelBuilder.rebuildColors();
}
$images.each(function() {
this.onload=function() {
loaded++; testRebuild();
}
this.onerror=function() {
$(this).hide();
loaded++; testRebuild();
}
$(this).attr("src", $(this).attr("data-original-front-src"));
});
我想你可以使用图像标签的onload事件。您想在加载图像时调用该函数吗?我应该提到的是,其中一些图像不存在,并且被错误处理程序隐藏,因此加载的变量永远不会到达总变量
var total = $images.length,loaded=0;
function testRebuild() {
if (loaded==total) wheelBuilder.rebuildColors();
}
$images.each(function() {
this.onload=function() {
loaded++; testRebuild();
}
this.onerror=function() {
$(this).hide();
loaded++; testRebuild();
}
$(this).attr("src", $(this).attr("data-original-front-src"));
});