react-request-fullscreen
Request fullscreen feature for browsers, used as a react component.
npm install
npm i react-request-fullscreen
Demo
Usage
FulllScreen is a react component, so you can do like this.
;
{ return <FullScreen /> ;}
After that, use the FulllScreen refs(fullScreen()
) to request or exit fullscreen feature for browsers.
// import FullScreen, { fullScreenSupported } from 'react-request-fullscreen' Component { superprops thisstate = isFullScreen: false } { this } { thisfullScreenRef } { thiselFullScreenRef } { const isFullScreen = thisstate return <div className='app'> <p>Browser support fullscreen feature: ``</p> <p>Browser is fullscreen: ``</p> <FullScreen ref= { thisfullScreenRef = ref } onFullScreenChange=thisonFullScreenChange> <div className='rq' onClick=thisrequestOrExitFullScreen > !isFullScreen ? 'Request FullScreen' : 'Exit FullScreen' </div> </FullScreen> <FullScreen ref= { thiselFullScreenRef = ref }> <div className='el-rq' ref= { thiselRef = ref } onClick=thisrequestOrExitFullScreenByElement > !isFullScreen ? 'Request FullScreen by Element' : 'Exit FullScreen by Element' </div> </FullScreen> <br /> <a href='https://github.com/TUBB/react-fullscreen'>GITHUB</a> </div> } ReactDOM
Please see Demo project for detail.
API
FullScreen.fullScreen(element?: HTMLElement)
request or exit fullscreen feature.fullScreenSupported()
whether fullscreen feature is supported for the browser.isFullScreen()
the browser is fullscreen or not.
Note
Most code is come from chrisdickinson/fullscreen