0

I have to fit all the images on a screen with every screen resolution.

Which should i use $(window) or $(document) to measure height /width to auto fit images.

Vinay
  • 6,891
  • 4
  • 32
  • 50
Johan
  • 79
  • 8

3 Answers3

0

You Need to get the $(window).

The window includes document. The window is the browser-screen, so the viewable area on screen, while document is your document. So the html page that is loaded into the browser, this can be smaller than your screen size.

Tim
  • 9,351
  • 1
  • 32
  • 48
  • See this has the same answer http://stackoverflow.com/questions/9431050/difference-between-window-width-vs-document-width – Tim Jul 31 '12 at 06:27
0

If there is no fixed height for all the images, then use

$(window).load(function () {
    // your code goes here which will be executed once all the images 
   // got loaded (seen)
});

In case the height is fixed for all the images you are loading, then do not wait for the images to be loaded, just assign fixed height to <img> tags and fit them. Use

$(document).ready(function () {
    // your code goes here which will be executed once the DOM is ready 
    // (means all the tags including IMG tags) are loaded. 
});
codef0rmer
  • 10,284
  • 9
  • 53
  • 76
0

I use window like this:

function resizeThings(){
var  winH = $(window).height();
var  winW = $(window).width();

// let's say you are trying to match images to height
 $('img').each(function(){
   $(this).css('height', winH); 
 });    

};

Jory Cunningham
  • 744
  • 5
  • 6