YouTube iframe player - trigger fullscreen on iOS

前端 未结 3 2068
旧时难觅i
旧时难觅i 2021-02-20 04:44

Using the YouTube iframe embed player, is there a way to trigger fullscreen programatically? I want to remove the default controls (using controls=0) but then have the ability t

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-20 04:59

    Make the iframe not fullscreen but fullpage:

        function fullscreen() {
            var vid = document.getElementById("vid");
            vid.style.position = "absolute";
            vid.style.width = "100vw";
            vid.style.height = "100vh";
            vid.style.top = "0px";
            vid.style.left = "0px";
            document.getElementById("exit").style.display = "inline";
        }
        function exitfullscreen() {
          var vid = document.getElementById("vid");
          vid.style.position = "";
          vid.style.width = "";
          vid.style.height = "";
          vid.style.top = "";
          vid.style.left = "";
          document.getElementById("exit").style.display = "none";
        }
    
        
        

    The full page button in the right upper corner of the code snippet also works this way. If you want to make the browser full screen you could try document.requestFullscreen();, but this is still experimental and works on very few browsers. Take a look at the MDN topic of this function.

    EDIT: Just found this: https://developers.google.com/youtube/?csw=1#player_apis, the official youtube player API.

提交回复
热议问题