Learning Three.js

or WebGL for Dummies

Window Resize for Your Demos

It is cool when you look at a demo and it is resized automatically when you change the dimension of the browser’s window. To switch it fullscreen or such. THREEx.WindowResize is an little piece of code. It helps you do exactly that on your own demos in a single line.

Let’s include the script

You download it from here and include it in your page like this

<script src='THREEx.WindowResize.js'></script>

Let’s use it

Now that the script is included, simply call the following line, and you are done! Your renderer will follow the window size.

THREEx.WindowResize(renderer, camera);

As usual you got a renderer and a camera variable, just pass them to the function and they will be updated on window resize.


For more details, see the annoted source of THREEx.WindowResize.