1

I want to display temporary image in an HTML page until original image is loaded. How can I do that?

<!-- IMG -->
<img src="original.jpg" temporary-img="temp.jpg"/> <!-- i have no idea how to do that ! -->
WillardSolutions
  • 2,267
  • 4
  • 30
  • 35
Robeala
  • 81
  • 1
  • 8

2 Answers2

4

If the original image is still loaded you can make the following in the HTML:

<img src="temp.jpg" id="img" data-original-img="original.jpg"/>

If the DOM is loaded, you can use the image, eg. Exchange as follows:

$(function() {
  $('#img').attr('src', $('#img').attr('data-original-img'));
});

Or with Plan JS: http://www.w3schools.com/jsref/event_onload.asp

Daniel
  • 116
  • 1
  • 5
1

You can add a background image using CSS.

img {
  background: url('temp_image.png') no-repeat;
}
the-petrolhead
  • 527
  • 1
  • 5
  • 14
  • @RajshekarReddy it's not stupid... css load the background with a temporary image and when the image is load she's hover the background... it can help OP – Alexis Dec 28 '16 at 13:59
  • This doesn't work in case the loaded image has a transparent background, in which case you will see the default image in the back :( – Felipe Jun 18 '17 at 13:42