0

How can I call a Javascript from a local .js file when the window is resized?

Here is the code in my .js file, which may or may not work because I can't figure out how to call it, but that's besides the point...

function sizeGutter()
{
    var p = document.getElementById("MIIHomeBtn");
    var offset = p.offsetTop + p.offsetHeight;
    document.getElementById("gutterDiv").style.top = offset + "px";
    document.getElementById("gutterDiv").style.height = document.getElementById("gutterDiv").offsetHeight - offset + "px";
}

And then I want to put window.onresize = sizeGutter; into my html, but I'm not really sure how, or if that is even the right approach.

Please help.

9
  • <body onload="window.onresize = sizeGutter;"> Commented Jul 17, 2015 at 23:21
  • 1
    Perfect. Thank you! Commented Jul 17, 2015 at 23:23
  • @John writing it in attribute is a bad idea. Commented Jul 17, 2015 at 23:24
  • just write window.onresize = function1 and etc. or use jquery. Commented Jul 17, 2015 at 23:24
  • Where would I write window.onresize = myFunction if not in the attribute? Commented Jul 17, 2015 at 23:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.