Changing window.onresize to window.addEventListener('resize', function)

Its recommended to use addEventListener.
I've also added a name to the anonymous function to make stack traces readable.