jquery - Javascript Image() return wrong Width and Height -
i'm using cross-slide jquery plugin , have doubt.
when try load image dimensions 1176 x 1168, .width
propertie return 600 , .height
propertie return 595.
why don't return current dimensions of image ?
plugin code:
// first preload images, while getting actual width , height (function (proceed) { var n_loaded = 0; function loop(i, img) { // (i = 0; < plan.length; i++) independent var i, img (for closures) img.onload = function (e) { n_loaded++; // here doubt plan[i].width = img.width; // returning 600 plan[i].height = img.height; // returning 595 if (n_loaded == plan.length) proceed(); } img.src = plan[i].src; if (i + 1 < plan.length) loop(i + 1, new image()); } loop(0, new image()); })(function () { // proceed ...
you need modify code bit (mainly loop
function) , try again, this:
function loop(i, img) { img.src = plan[i].src; img.onload = function (e) { n_loaded++; plan[i].width = this.width; // check width plan[i].height = this.height; // check height if (n_loaded == plan.length) proceed(); } if (i + 1 < plan.length) loop(i + 1, new image()); }
Comments
Post a Comment