I've noticed the $.resize()
event of jQuery is fired on page load without any actual "resize" of the window depending on the browser.
It is not only fired once, but even twice sometimes. (on load in Chrome 30.0.1599.101 m, on resize in Opera...)
Is this behave normal? Isn't there any way to unify this behavior on loading of the site for all browsers?
I'm already calling the resize
only once when resizing have already finished (using an interval), but this doesn't solve the problem of the event being fired on load for Chrome.
I couldn't create a fiddle reproducing this problem, but you can test this behavior with a file like this:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(window).resize(function() {
alert("Fired!");
});
</script>
</head>
<body>
</body>
</html>
The event will be fired the first time you load the page with Chrome. It won't be fired on any refresh of it.
$(document).ready(function() { $(window).resize(function() { alert("Fired!"); }); });
I'm not sure if this is the answer you are looking for as you ask two separate questions in your text that are somewhat disjoint from the title of this post. – Gaddy