1

I can't get this to work and am at my wits end. The code will not fire an event!

This is what I have, the math is custom to the page. I need to reset the bodyWrapper height when the window is resized to prevent overflow on top of another div.

<script type="text/javascript">
  window.onresize = function() {
    var height = window.height();
    var wrapper = height - 286;
    document.getElementById('bodyWrapper').style.height = wrapper;
  };
</script>

<div class="body-wrapper" id="bodyWrapper" style="height: 50px;">
halfer
  • 19,824
  • 17
  • 99
  • 186
CFitz
  • 25
  • 1
  • 7
  • Most likely there is something else on the page overwriting you onresize event, try using window.addEventListener("resize", function(){}); – Alexander O'Mara Jan 03 '14 at 22:12
  • In my browser, `window` does not have a "height" property at all. Have you checked your developer console for errors? – Pointy Jan 03 '14 at 22:13
  • Pointy raises a good point, this code will most-likely error-out. Are you sure the event is not firing, or is it simply failing? – Alexander O'Mara Jan 03 '14 at 22:16
  • i think window.innerHeight is what you're after ( https://developer.mozilla.org/en-US/docs/Web/API/Window.innerHeight ) – GameAlchemist Jan 03 '14 at 22:23
  • Its window.OnResize events wont fire if incorrectly called. – Cam Jan 03 '14 at 22:25
  • Check out the second answer – http://stackoverflow.com/questions/526347/css-javascript-how-do-you-get-the-rendered-height-of-an-element height() is jQuery, not vanilla JS. – Ian Jan 03 '14 at 22:45

0 Answers0