react 全屏显示实现
import { Button } from 'antd';
import screenfull from 'screenfull';
import { useRef, useState } from 'react';
const InfoBoard: React.FC = () => {
const containerHandler = useRef(null)
const [fullscreen, setFullscreen] = useState(false)
const handleClick = () => {
if (screenfull.isEnabled) {
/**
* 应用内特定Dom对象全屏
*/
//screenfull.request(containerHandler.current);
//整个页面全屏
screenfull.request();
setFullscreen(true)
}
}
return (
<>
<div ref={containerHandler}>
<div>
<button onClick={handleClick}>
Enter fullscreen
</button>
</div>
</div>
</>
);
};
export default InfoBoard;