views:

25

answers:

1

window.resize event in IE doesnt do what i thought it does.

I thought it only triggered when the physical window/view-port changed size (ie user hits maximize on the browser window for example), but it is also triggered if i change the document size, introducing scroll bars.

is there any way to tell those two things apart: view port resize, and document resize without writing an elaborate hack?

A: 

No takers? well here is the hack (not tested - but the idea is right)

function viewPortResize(fn, context){
  context = context || window;
  var $window = $(window);
  var winWidth = $window.width();
  var winHeight = $window.height();

  return function(e){
    var oldW = winWidth;
    var oldH = winHeight;
    winWidth = $window.width();
    winHeight = $window.height();
    if (winWidth != oldW || winHeight != oldH){
      fn.apply(context, [e]);
    }
  }
}


//use:
$(window).resize(viewPortResize(function(e){
    alert("this only happens when viewport is resized!");
});
mkoryak
also, one must take care the case when window is resized only because a scroll bar is introduced.
mkoryak