2

Here is where I'm at:

onResize = (function($) {
//Do stuff 
});
$(document).ready(onResize);
$(window).bind('resize', onResize);

The script calculates the width of it's containing div and then lays out a gallery accordingly. It runs onload correctly (no matter the window width ) but doesn't seem to fire on resize. The issue? Creates layout problems with my media Queries.

Justin W Hall
  • 371
  • 1
  • 5
  • 21
  • The issue is discussed here: http://stackoverflow.com/questions/641857/javascript-window-resize-event and here: http://stackoverflow.com/questions/599288/cross-browser-window-resize-event-javascript-jquery – valentinas Jan 27 '12 at 01:38
  • The problem might be that you expect `$` to refer to `jQuery`. This is true when the function is called as `ready` callback, but as response to the `resize` event, it will refer to the event object. Other than that, the code you posted looks fine. – Felix Kling Jan 27 '12 at 02:36
  • possible duplicate of [jQuery resize function doesn't work on page load](http://stackoverflow.com/questions/2597152/jquery-resize-function-doesnt-work-on-page-load) – davidcondrey Jun 09 '15 at 09:01

2 Answers2

0

Your code runs correctly in Chrome.

Alex
  • 2,350
  • 2
  • 20
  • 17
0

Justin W Hall, I tried this in my chrome console:

onResize = (function($) { console.log('resized') });
    console.log('resized')
});
$(document).ready(onResize);
$(window).resize(onResize);

and it worked just fine.

ps. If you run this code, you'll notice that onResize function fires two times (showing 2 'resized' messages) when you resize the window.

Bengineer
  • 7,264
  • 7
  • 27
  • 28