当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Work with images sizes after AJAX load in Coffeescript

问题描述:

I have a bunch of images which is on a page that is injected into another page using AJAX.

When the images are injected I want to run through them, set the shortest side to 64px and then clip the image to 64x64 pixels (have the 'viewport' in the top middle).

I have a method which iterates over all images and do the logic as it should. But it seems to run before the images get their correct size. I get that it's because the browser doesn't resize until the DOM is loaded.

I have tried a bunch of stuff like using load() and creating images in memory (is this really size to do for each images? feels bad performance-wise).

Any ideas?

网友答案:

You can use simple Ajax start and ajax complete function. An example given below:

$(document).ajaxStart ->
  $("#accordion2").css "opacity", "0.4"
  return

$(document).ajaxComplete ->
  $("#accordion2").css "opacity", "1.0"
  #You can call your Image Load function here
  return
分享给朋友:
您可能感兴趣的文章:
随机阅读: