js让页面某个元素全屏(比如视频)的方法

<video src="a.mp4" muted autoplay></video>

    <a onclick="openFullscreen();">full</a>
    <script>

var elem = document.getElementsByTagName("video")[0];

function openFullscreen() {
  if (elem.requestFullscreen) {
    elem.requestFullscreen();
  } else if (elem.mozRequestFullScreen) { /* Firefox */
    elem.mozRequestFullScreen();
  } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
    elem.webkitRequestFullscreen();
  } else if (elem.msRequestFullscreen) { /* IE/Edge */
    elem.msRequestFullscreen();
  }
}

// openFullscreen();

    </script>

 

js让页面某个元素全屏(比如视频)的方法
标签: