0

I have this code on my page:

<div class="titleCard" id="first" style="background-image:url('img/path.jpg'); filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/path.jpg',sizingMethod='scale'); -ms-filter: \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/path.jpg',sizingMethod='scale')\";">

How in jquery can I test whether the image has loaded? I want to have a title fade up on top of the image once it's done loading.

This seems to be different from other loading issues because the .load() function doesn't work here -- the image has no id. Calling it '#first' or '#first img' also doesn't work. I don't want to check whether all images or loaded, just this one. Binding the load function also doesn't seem to work.

LauraNMS
  • 2,420
  • 7
  • 29
  • 63

1 Answers1

0

You can use JS to load the image in memory and listen to the onload event there. You'll need to set the default opacity, then fade in on your onload event.

var tmp = new Image();
tmp.onload = function() { ... };
tmp.src = "....";
Diodeus - James MacFarlane
  • 107,156
  • 31
  • 147
  • 171