Reputation: 22404
I have some code like the following:
var f = function() {...};
$(window).resize(f);
f();
As you can see, I'd like f
to be called every time the window is resized, and also for f
to be called once after I make it the resize event handler.
Is there any way I can make this code shorter/more succinct? Ideally I'd like to eliminate the need for an f
variable and just make it an anonymous function (i.e. $(window).resize(function() {...}
), but I need some way of calling the function once...
Upvotes: 3
Views: 69
Reputation: 356
$(window).
resize(function () {console.log("stop resizing me!");}).
resize();
Upvotes: 2
Reputation: 207527
Well you will not make it shorter, but this is one way you can trigger it instead of the f()
.
$(window).resize(f).trigger("resize");
Upvotes: 6