Dave McCabe
Dave McCabe

Reputation: 11

JQUERY and window resize

this may seem a simple question regarding Jquery and twitter bootstrap

I have a twitter bootstrap, fluid layout, when the windows resizes, the fluid rows obviously resize, but I notice these <div>s don't get or issue .resize events

I can detect the browser windows resize useing $(window).resize, but even though the child elements resize , attaching a resize handler to them does not result in a resize event trigger

I know you might say that resize events only bubble 'up', but surely if div is resizing, due to the browser window resizing ( and via bootstrap CSS) it should get a resize event.

Upvotes: 1

Views: 496

Answers (1)

James Montagne
James Montagne

Reputation: 78630

Your best bet is to simply put the resize handler on the window and deal with any resize related changes which are needed throughout the content of the page in that one handler.

Alternatively, you could trigger a custom event on your elements when the window is resized:

$(".resizer").on("customresize", function(){
    var $this = $(this);
    $this.text($this.width());
});

$(window).resize(function(){
   $(".resizer").trigger("customresize"); 
});

http://jsfiddle.net/vs8Q8/

Upvotes: 3

Related Questions