How to make Three.js fullscreen?

I want to make a game with Three.js, but how to make it in full screen? I saw this article and I included THREEx in my code, but when I do this: THREEx.FullScreen.request()nothing happens! I looked at the THREEx code and changed it like this: for debugging purposes:

THREEx.FullScreen.request   = function(element)
{
    element = element   || document.body;
    if( this._hasWebkitFullScreen ){
        element.webkitRequestFullScreen();
        console.log("f");
    }else if( this._hasMozFullScreen ){
        element.mozRequestFullScreen();
        console.log("g");
    }else{
        console.assert(false);
    }
}

So this default value is to create document.body full screen mode and it prints "f" in the console. But nothing! There are no error messages in the console or anything else ... And I tried my example with the pool, it works, so I am sure that this is not an error of my computer ...

+3
source share
1 answer

You should:

  • , , . keydown. , , . -, , , , , .
  • , document.
  • request this THREEx.FullScreen ( , ).

, :

document.body.addEventListener("keydown", function() {
  THREEx.FullScreen.request();
}, false);
+5

All Articles