Getting image width on image load fails on IE

后端 未结 8 1447
自闭症患者
自闭症患者 2020-12-31 09:32

I have a image resizer function that resize images proportional. On every image load a call this function with image and resize if its width or height is bigger than my max

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 10:22

    Try

     function onImageLoad(img, maxWidth, maxHeight) {
       var width = img.width; // Problem is in here
       var height = img.height // Problem is in here
       if (height==0  && img.complete){
           setTimeOut(function(){onImageLoad(img, maxWidth, maxHeight);},50);
       }
    
     }
    

提交回复
热议问题