How do I make a div full screen?

后端 未结 10 1887
耶瑟儿~
耶瑟儿~ 2020-12-07 10:59

I am using Flot to graph some of my data and I was thinking it would be great to make this graph appear fullscreen (occupy full space on the monitor) upon clicking on a butt

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 11:16

    Can use FullScreen API like this

    function toggleFullscreen() {
      let elem = document.querySelector('#demo-video');
    
      if (!document.fullscreenElement) {
        elem.requestFullscreen().catch(err => {
          alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
        });
      } else {
        document.exitFullscreen();
      }
    }
    

    Demo

    const elem = document.querySelector('#park-pic');
    
    elem.addEventListener("click", function(e) {
      toggleFullScreen();
    }, false);
    
    function toggleFullScreen() {
    
      if (!document.fullscreenElement) {
        elem.requestFullscreen().catch(err => {
          alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
        });
      } else {
        document.exitFullscreen();
      }
    }
    #container{
      border:1px solid #aaa;
      padding:10px;
    }
    #park-pic {
      width: 100%;
      max-height: 70vh;
    }

提交回复
热议问题