Function returns the value before Jquery Image load is executed

后端 未结 2 1373
孤独总比滥情好
孤独总比滥情好 2021-01-25 10:29
if (DataService.Validation(file)) {
    //angularjs call to api controller
};    

//DataService
Validation: function (file) {
    var Url =   URL.createObjectURL(file);         


        
2条回答
  •  青春惊慌失措
    2021-01-25 11:11

    The behaviour is correct as your function will return with 'true' value always. IMG load function will execute only after your image is completely loaded by the browser and since its asynchronous your function will not wait for it to execute. Also if you want to check the width/height of image being loaded, use naturalWidth/naturalHeight as this will give the right values and not the one assigned to the image by css.

    What you can do is inside image-load function,you can call your function with true/false value as parameter.

提交回复
热议问题