I have run into issues recently with the browsers’ implementation of the resize event on the window. Opera, Safari, IE and Firefox all have different behaviors when this event is fired.
- Firefox only fires it when you release the mouse.
- IE fires this event many many times while resizing.
- Safari will fire continusouly while dragging
- Opera fires after the resizing stopped
You can read more about this here.
These differences led me to search for a solution. I quickly wrote this proof of concept function today which may help solve this problem. It is a JQuery add-on called resizeComplete. It works by checking periodically after a resize starts and checks if the size of the object has changed. Once no change is detected it invokes the call back method.
This has not been tested much at all but I think it might be on the right track.
jQuery.fn.resizeComplete = function(callback) { var element = this; var height = element.height(); var width = element.width(); var monitoring = false; var timer; function monitorResizing() { monitoring = true; var newHeight = element.height(); var newWidth = element.width(); if(newHeight != height || newWidth != width) { height = newHeight; width = newWidth; timer = setTimeout(function() { monitorResizing() },100); } else { monitoring = false; clearTimeout(timer); callback(); } } function onResize() { if(monitoring) return; monitorResizing(); } element.resize(onResize); }
Here is an example of its usage:
$(document).ready(function() { $(window).resizeComplete(function(){ document.write('hi') }); });