I have this code where I need to call a function multiple times.
$(window).resize(function() {
centerBox();
});
$(window).scroll(function() {
centerBox();
});
centerBox();
And I realise this is incredibly messy. Is there any better way to write this?
You can shrink your code to 3 lines:
And of course you have to define your function on top
Or you also can use it in 2 lines by combining it, but that would also be a little messy: