jaysalvat/vegas — Issue #13: Wrong Resize at PageLoad
Author: rvetere
Created: 2012-03-06 07:39:08+00:00
State: open

I have noticed, that in some cases of image-sizes, vegas-plugin will not correctly resize the image at page-load. The event of the image-load plugin "imagesLoadedForVegas" is called too early - or, at least, the image-element is responding for getWidth() and getHeight() with 0.

To solve this problem, i have just implemented a kind of a wait-for-element logic inside of the initialization of the plugin.

Somewhere at line 98-100, there is the first "resize" call -> at this line, i've replaced that single line of code with the "resize" with that one:

```javascript
/**
* Wrong-Initial-Dimension-Fix
* @author Remo Vetere
*
* Logical fix for initial resize operation -> if the image returns 0 on getWidth(), the resize logic
* is screwed up -> and on this line of the code, it will always return 0. So, we simply make a wait-for-element
* logic to resize imediately the image is successfully inserted into the dom -> a time value that is extremely
* different, depending on the platform and the browser-engine.
*/
var waitForElement = function() {
if ($current.width() == 0) {
setTimeout(waitForElement, 25);
} else {
resize( $current, options );
}
};
waitForElement();
```