donderdag 6 september 2012

Trigger resize event with jQuery cross-browser

Bind an event handler to the "resize" JavaScript event, or trigger that event on an element

jQuery has a built-in method for this:

$(window).resize(function () { /* do something */ }); 

For the sake of UI responsiveness, you might consider using a setTimeout to call your code only after some number of milliseconds, as shown in the following example, inspired by this:

function doSomething() { 
alert("I'm done resizing for the moment");

var resizeTimer;
$(window).resize(function() {
resizeTimer = setTimeout(doSomething, 100);

Geen opmerkingen:

Een reactie posten