Check if <img> has width and height attributes before setting them #51

Closed
marijoo opened this Issue Sep 14, 2012 · 2 comments

Comments

Projects
None yet
3 participants

marijoo commented Sep 14, 2012

If images are invisible on the page retina.js will give the replaced versions the dimensions of 0x0.
Fixed it like this:

if (t.el.complete) {
if (parseInt(t.el.getAttribute("width"), 10) > 0) {
t.el.setAttribute("width", t.el.getAttribute("width"));
} else {
t.el.setAttribute("width", t.el.offsetWidth);
}
if (parseInt(t.el.getAttribute("height"), 10) > 0) {
t.el.setAttribute("height", t.el.getAttribute("height"));
} else {
t.el.setAttribute("height", t.el.offsetHeight);
}
t.el.setAttribute("src", e);
} else {
setTimeout(n, 5);
}

Contributor

caseyohara commented Oct 8, 2012

@marijoo Can you submit this as a pull request so we can review and test it?

Contributor

taylorsmith commented Jul 31, 2014

This problem should be fixed in #106.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment