Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the jQuery resize event fire twice?

Tags:

I just noticed that the jquery resize event fires twice any time the browser window is resized. I'm unable to find any documentation listing this as the default behavior. I have tested this in the latest versions of Chrome and Firefox, using jQuery 1.4 and 1.5.

Does anyone else see this behavior? Is there a specific reason for it?

Update: This happens if I click the maximize button on the browser window once. I understand that if I'm manually dragging the window to a different size, the event will be fired multiple times, but that shouldn't be the case with the maximize button.

The code used test this is below. The browser resized text is output twice:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"         "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>     <title></title> </head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script> <script type="text/javascript">     $(window).resize(function(){         console.log('Browser Resized');     }); </script> <body>  </body> </html> 
like image 439
Mark Brown Avatar asked Apr 04 '11 03:04

Mark Brown


People also ask

What is Resize event in jQuery?

The resize event occurs when the browser window changes size. The resize() method triggers the resize event, or attaches a function to run when a resize event occurs.


1 Answers

JQuery: How to call RESIZE event only once it's FINISHED resizing?

Shows at least others are having this issue. In 1.3.2 it was listed as a bug because of something with the events system: http://benalman.com/code/projects/jquery-resize/docs/files/jquery-ba-resize-js.html

like image 84
jnpdx Avatar answered Sep 22 '22 06:09

jnpdx