0

I have this function to adjust the page so that it does not scroll regardless of the device, it works at all, however, when you rotate the screen or when I change the device to inspect Google Chrome, the function does not work well, only if I do the reload on the page that works, I don't know what I'm doing wrong. I believe the problem is in the variable h, where it picks up the height, which doesn't pick up the height when modifying or rotating the device, but I'm not sure, I've tried everything

function changeSize() {
  let h = $(document).height();
  let he = $("header").height();
  let m = $("main").height();
  let f = $("footer").height();
  let l = $("ui-loader").height();
  let x = h - he - m - f - l;
  $("container").css('height', x + 'px');
}

$(document).ready(function() {
  changeSize();
  $(window).resize(function() {
    changeSize();
  });
};
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
ellen
  • 11
  • 2
  • You could try adding `deviceorientation` as an event handler? (i.e. `$(window).on('deviceorientation', changeSize);`) – freefaller Jul 21 '20 at 14:22
  • 1
    Does this answer your question? [Will $(window).resize() fire on orientation change?](https://stackoverflow.com/questions/23996726/will-window-resize-fire-on-orientation-change) – Nawed Khan Jul 21 '20 at 14:23
  • No :( I already tried this and didnt work – ellen Jul 21 '20 at 14:31
  • You already [asked this question yesterday](https://stackoverflow.com/questions/62995632/jquery-window-resize-not-working-just-reloading). For future reference, when asked to add detail to a question edit the existing one. Do not start a new one. – Rory McCrossan Jul 21 '20 at 14:50

1 Answers1

0

The first issue I see is here:

  let he = $("header").height();
  let m = $("main").height();
  let f = $("footer").height();
  let l = $("ui-loader").height();
  $("container").css('height', x + 'px');

These do not select any element. Are they Class selectors or ID Selectors? I will assume Class selectors for my Example.

function changeSize() {
  let h = $(document).height();
  let he = $(".header").height();
  let m = $(".main").height();
  let f = $(".footer").height();
  let l = $(".ui-loader").height();
  let x = h - he - m - f - l;
  $(".container").css('height', x + 'px');
}

$(function() {
  changeSize();
  $(window).on("resize deviceorientation", changeSize);
};

Another issue I see here is that this does not capture any Padding or Margins.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Twisty
  • 30,304
  • 2
  • 26
  • 45