代码之家  ›  专栏  ›  技术社区  ›  Mithun Sreedharan Kuldeep Modi

JQuery—如何找到是否所有图像都是从Ajax响应加载的

  •  1
  • Mithun Sreedharan Kuldeep Modi  · 技术社区  · 16 年前

    参见下面的代码, #gridWrapper 来自Ajax响应,它有很多缩略图。

    success: function(Data){
     MyGrid.prepGridLayout(Data.html);
     $('#gridWrapper .thumbnail img').load(function(index) {
      MyGrid.updateCellWidth(this);
     });
     MyGrid.adjustGridWidth();
     MyGrid.animateGridLayout();
    }
    

    我需要执行 MyGrid.animateGridLayout(); MyGrid.animateGridLayout(); 是在 MyGrid.updateCellWidth(this); 执行

    如何确保 MyGrid.animateGridLayout(); 仅在加载所有图像后运行?

    1 回复  |  直到 16 年前
        1
  •  2
  •   Pointy    16 年前

    你可以让“加载”处理程序记录他们做了多少。

    success: function(Data){
      MyGrid.prepGridLayout(Data.html);
      var thumbs = $('#gridWrapper .thumbnail img'), tc = 0;
      thumbs.load(function(index) {
        MyGrid.updateCellWidth(this);
        if (++tc === thumbs.length) {
          MyGrid.adjustGridWidth();
          MyGrid.animateGridLayout();
        }
       });
    }