javascript - Bypassing async while getting image size -
I get the size of the image (width x height) The location of the image is the url. I tried something like below the code block
var constant: {standImgDim: {small: '200x200', middle: '400x400'}};
this.getImgDim = functionImg {var width = 0, height = 0, setStyleWidth = 0; $ ("& lt; img / & gt;") .attr ("src", targetImg) .load (function () {width = this.width; height = this.height; var found = width = 'x' + Height; console .log (gotDim);}); Console.log ('data'); }; Expected output: data 200x200 Expected output:
200x200 data < p> I know that the result of ASCIC behavior is coming ... I also tried it with $$. Defined .. but this will not work as I have been in the form of Ajax (below) Not in
var deferred = new $ Idle (); $ .ajax ({type: "GET", url: target IMG, datatype: "image / JPEG"}) (function (data) {deferred. }) Unsuccessful (function (error) {deferred.reject (error);}); Refund suspended. Is there any way to do this in sync mode / other?
Add callback to the load function:
this.getImgDim = function (Target IMG, callback) {var width = 0, height = 0, setStyleWidth = 0; $ ("& lt; img / & gt;") .attr ("src", targetImg) .load (function () {width = this.width; height = this.height; var found = width = 'x' + Height; console ;log (gotDim); callback ();}); }; this.getImgDim ('targetImage', function () {console.log ('data');}); Anxink is only .load , therefore allows callback, some synchronous reference is the code to come back, if you need access Some output data of variables or load functions, you can pass it through the callback. I think that you can pass through the same reference by:
callback .bind (this);
Comments
Post a Comment