Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug where images loaded from chrome cache results in 0 WIDTH elements #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/spritespin.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,13 @@
var h = Math.floor(data.height || data.frameHeight || data.target.innerHeight());

if (data.responsive && (typeof window.getComputedStyle === 'function')) {
var style = getComputedStyle(data.target[0]);
if (style.width) {
var styleWidth = getComputedStyle(data.target[0]).width;
// The image ("data.target[0]") can be loaded from the browser cache, which in some cases makes
// "getComputedStyle().width" return the "auto" value (resulting in "w = 0").
// Not sure if the "inherit" and "inital" cases are possible, but it doesn't hurt to prevent.
if (styleWidth && styleWidth !== 'auto' && styleWidth !== 'inherit' && styleWidth !== 'initial') {
var a = w / h;
w = Number(style.width.replace('px', ''))|0;
w = Number(styleWidth.replace('px', ''))|0;
h = (w / a)|0;
}
}
Expand Down