Val
Val

Reputation: 17522

jquery window resize help please

$(window).resize(foo())

to detect when the window is resizeing...

the foo() works fine but it only fires foo() after the resize has finished so it's not while resizeing.

is there a way to make the resize smoothly. maybe a cancelBubble could be something to do with it but im not familiar with it.

Upvotes: 2

Views: 2278

Answers (4)

Darrell
Darrell

Reputation: 51

From the jQuery documentation, you seem to be experiencing Firefox behavior when you're really after IE behavior.

Depending on implementation, resize events can be sent continuously as the resizing is in progress (the typical behavior in Internet Explorer and WebKit-based browsers such as Safari and Chrome), or only once at the end of the resize operation (the typical behavior in Firefox). http://api.jquery.com/resize/

Interestingly, on that same page is a comment to a plugin which may make the behavior cross-browser (I have not looked into this)

Upvotes: 2

Mike
Mike

Reputation: 5036

You can't do precisely what you want by listening to window resize events.

Check out Google maps or reader, try resizing the window vertically. Note that these apps exhibit the same behavior.

Look a bit more carefully at your CSS. I find that sometimes CSS can do some very surprising things. If you post some sample HTML and CSS that is representative of you problem, we may be able to devise a solution.

If you absolutely cannot tolerate waiting until the user has finished resizing the window, you could poll document.scrollWidth and document.scrollHeight at a short interval. Whenever they change, call your resizing code. Note that polling these properties may be pretty expensive. I recommend against this, but it will solve the problem.

If you are using Internet Explorer, depending on version, you made need to use document.documentElement.scrollWidth or document.body.scrollWidth (and similar for scrollWidth).

Firefox 3.6 will support events for determining when document.scrollWidth and document.scrollHeight change, although it looks like it will be non-standard:

https://developer.mozilla.org/en/DOM/Detecting_document_width_and_height_changes

Upvotes: 3

RichN
RichN

Reputation: 6231

The resize event fired after the window has finished resizing is pretty much the way things are. I don't think you can do anything about it.

Upvotes: 2

jrharshath
jrharshath

Reputation: 26583

It makes me wonder why you would want to do such a thing. If you could be specific, perhaps I could suggest a CSS solution to you?

Upvotes: 0

Related Questions