Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在图像元素更改其src后计时函数运行_Javascript_Jquery - Fatal编程技术网

Javascript 在图像元素更改其src后计时函数运行

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属性。加载新图像后,我想运行一个名为wheelBuilder.rebuildColors()的函数

这段代码在某些浏览器(chrome、safari、ie)上运行良好,但在Mozilla firefox上不起作用

是否有办法将其设置为在加载所有图像后运行该函数


谢谢,试试这个。您必须在更改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"));
});