JQuery - how to wait for the end or resize event and only than perform action?

I had luck with the following recommendation: forum.jquery.com/topic/the-resizeend-event Here's the code so you don't have to dig through his post's link & source: var rtime = new Date(1, 1, 2000, 12,00,00); var timeout = false; var delta = 200; $(window). Resize(function() { rtime = new Date(); if (timeout === false) { timeout = true; setTimeout(resizeend, delta); } }); function resizeend() { if (new Date() - rtime.

You can use setTimeout() and clearTimeout() var doit; $(window). Resize(function(){ clearTimeout(doit); doit = setTimeout(function(){resizedw();}, 100); }); Code example on jsfiddle.

This is a great answer. It does what the plugin I recommended does, only without a plugin. – jessegavin Mar 30 at 17:48 +1 for writing up the example faster than I did :) – Demian Brecht Mar 30 at 17:51 I think the only way to really improve this is to detect mouse movement.

I suspect digging into it would not payoff, though. – Michael Haren Mar 30 at 18:19 Does this only work if the resize is finished within a second? My function was triggering when I tried using this (I was slow w/ my window resize though) – dolan Mar 300 at 6:54.

There isn't really a onResizeEnd event. Browsers will trigger the resize event many times while you're resizing. There's a really cool jQuery plugin that will allows you to either throttle or debounce an event.

Suppose you have this function that you want to trigger after a resize: function onResize() { console. Log("Resize just happened! "); }; Throttle Example In the following example, onResize() will only be called once every 250 milliseconds during a window resize.

$(window). Resize( $. Throttle( 250, onResize) ); Debounce Example In the following example, onResize() will only be called once at the end of a window resizing action.

This achieves the same result that @Mark presents in his answer. $(window). Resize( $.

Debounce( 250, onResize) ).

Using jQuery-UI and its resize controls gives you access to start/stop events... jqueryui.com/demos/resizable.

I don't think that is useful for window resizing – Karsten Mar 30 at 17:44 You're probably right, I didn't spot that it was with window... that said, its still useful for other elements. – Codecraft Mar 30 at 17:49.

Well, as far as the window manager is concerned, each resize event is its own message, with a distinct beginning and end, so technically, every time the window is resized, it is the end. Having said that, maybe you want to set a delay to your continuation? Here's an example.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions