diff options
| author | 8chan <admin@8chan.co> | 2014-06-10 18:50:14 +0000 |
|---|---|---|
| committer | Fredrick Brennan <admin@8chan.co> | 2014-06-10 18:50:44 +0000 |
| commit | 5a02cd61db118d08fe76f880cf57606b083fcea7 (patch) | |
| tree | 7426f2f5942c4473c0faefebc18c579a3c1fada7 | |
| parent | dfe8ddc34000685f5deaf504ffe78e8dd685681c (diff) | |
Fix issue when loading images in Chrome
| -rw-r--r-- | js/no-animated-gif.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/js/no-animated-gif.js b/js/no-animated-gif.js index cfdf757b..36d48954 100644 --- a/js/no-animated-gif.js +++ b/js/no-animated-gif.js @@ -13,7 +13,17 @@ function unanimate_gif(e) { $(e).parent().prepend(c); c.attr('width', $(e).width()); c.attr('height',$(e).height()); - c[0].getContext('2d').drawImage(e, 0, 0, $(e).width(), $(e).height()); + function draw_image() { + c[0].getContext('2d').drawImage(e, 0, 0, $(e).width(), $(e).height()) + }; + + // Fix drawing image before loaded. Note that Chrome needs to check .complete because load() is NOT called if loaded from cache. + if (!e.complete) { + e.onload = draw_image; + } else { + draw_image(); + } + $(e).hide(); } |
