0

Is it possible, via jQuery, to get the height of an background-image? The height in pixel? And if so, how to? I'm creating an lightbox, so i need the height to match the photos actual height exactly.

Thank you.

  • Magnus Pilegaard
Magnus Pilegaard
  • 393
  • 2
  • 4
  • 17

1 Answers1

0

I'm not sure whether you mean the height of the actual browser window which has a background image or the height of the image file used for the background. I'll try and help with both.

Height of browser window:

var height = $(window).height();

or

var height = $(document).height();

I normally use document height.

Height of Image: Check this thread out.

Incase the link breaks:

var img = document.getElementById('imageid'); 
//or however you get a handle to the IMG
var width = img.clientWidth;
var height = img.clientHeight;
Community
  • 1
  • 1
Jamie Scott
  • 452
  • 4
  • 20
  • I want to get the height of the jpg file added, background-image in css, then apply the height to the css, so the height of the a always is the size of the image – Magnus Pilegaard Aug 01 '15 at 10:51