0

How can I preload large background images before showing them to be used with the css background-image: url(image); format. I can use jQuery to make it easier.

mattdevio
  • 2,319
  • 1
  • 14
  • 28

1 Answers1

0
var img = document.createElement('img')
img.src = 'http://yourhref.com/myimg.jpg'

would load the image. With Css:

var div = document.createElement('div')
div.style.backgroundImage = 'url("myurl.jpg")'

Then, when you want to add it,

document.body.appendChild(div)
Zane Hitchcox
  • 936
  • 1
  • 9
  • 23