0

Ok so basically i'm using a gif as a background image, however i'd like it to display a static image until the gif has fully loaded and be ready to play.

Having read a few similar threads i know you can target elements with js and change them once they've loaded however the only examples i've seen target img tags and not a background image via css.

Heres a snippet if it helps

body {
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  width: 100%;
  height: 100%;
  background: #232228 url(../img/bg-center.jpg) top no-repeat; /* Static */
  background: #232228 url(../img/bg-center.gif) top no-repeat; /* Animated */
}
  • try this http://stackoverflow.com/questions/29742508/show-loading-gif-while-image-is-loading – Udhay Titus Jul 26 '16 at 04:15
  • Im not using image tags though, ive seen a few posts about it with image tags but cant find anything to specifically target only the background image – Izaak Lindsay Jul 26 '16 at 04:20
  • You should use an regular image so you can use an onload Event. There are no DOM Events for a background-image. – StackSlave Jul 26 '16 at 04:26
  • Why not use a canvas, and just have it display your static image until the gif is ready? If you want the element as a background, just use the z-index to draw it in the background. – Chris Jul 26 '16 at 04:27

1 Answers1

0

I am afraid that you will have to use JS for this, use images loaded plugin to see if the gif image is loaded then change the bg property

Shintu Joseph
  • 962
  • 7
  • 19