0

I'm using JQuery and JQuery-Mobile to show a simple UI with a header and a map. I want the map to fit the whole screen, so its height is set to the height of the window minus the height of the header.

My javascript is simple:

$(document).ready(function () {
    var maxWidth = $(window).width();
    var maxHeight = $(window).height();

    var headerHeight = $('#header').outerHeight(true);
    var heightMap = maxHeight - headerHeight;
    $('#map').css("height",heightMap);

The same lines are in the $(window).resize() function.

The map is well resized when the screen size changes, but the first time I load a page, in landscape, it's about 10 pixels heigher. How can I solve this?

Filburt
  • 17,626
  • 12
  • 64
  • 115
user3098549
  • 1,171
  • 2
  • 13
  • 26
  • Don't use `.ready()` in JQM, use page events. http://stackoverflow.com/questions/21552308/set-content-height-100-jquery-mobile/21553307#21553307 – Omar Mar 11 '14 at 09:09
  • 1
    Thanks, I solved by using $.mobile.getScreenHeight(); as I saw in your code! Now, I just have to fix the background size that is still bigger than the screen: I tried to resize the .ui-content and the body, but I still have a page bigger than screen size. Do you know what is the element that I have to modify? – user3098549 Mar 11 '14 at 09:58
  • Can you post a screenshot? Html code along with CSS? – Omar Mar 11 '14 at 10:04

1 Answers1

0

Use like this:

$(window).on('load resize',function(){
//your code in here
});
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231