Why not use Math.min(window.innerHeight, window.innerWidth) ?