MR.ABC
MR.ABC

Reputation: 4862

Element Background Image DataURL

Is there any way to get a callback on background-image is loaded with a base 64 DataURL. I can cache this with image src attribute, but with data url ? How ?

Upvotes: 0

Views: 310

Answers (2)

MR.ABC
MR.ABC

Reputation: 4862

Seems that style.BackgroundImage property do not set the value asynchronously. So my problem is solved.

Upvotes: 0

adeneo
adeneo

Reputation: 318182

Should work the way it usually does:

var image = new Image();
image.src = "data:image/  png;base64,iVBORw0KGgoAAAANSUh.......";
image.onload = function() {
    //image was loaded
};

Caching by the browser is of course disabled for Base64 strings, that's why it's normally only used for small images, like icons and stuff.

You can convert images to Base64 online here : http://base64img.com/#encode

Note that some browsers can have limitations on size for Base64.

Upvotes: 1

Related Questions