I have the following JavaScript/jQuery code in an HTML file:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"
type="text/javascript"></script>
<script language="javascript">
$(window).resize(function(){alert('hi');});</script>
</head>
<body>
resize me
</body>
</html>
It appears relatively straightforward, however when I resize the browser window, I get two successive alert windows on Chrome and IE9 and I seemingly crash Firefox5.
What am I missing? Is it one fire per dimension (x/y)?
You got it, some browsers fire on resize start and again on end while others like FF fire continuously. Solution is to use
setTimeoutto avoid firing all the time. An example can be found here. Here is the code from the same reference: