Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Modal in fullscreen

Is there a way to open a modal which will take entire screen just like in youtube video when you click on it's fullscreen it takes the entire screen view.

Right now this is what i have achieved so far

<Modal
      title={false}
      visible={visible}
      footer={false}
      centered
      width="100vw"
      onCancel={() => setVisible(false)}
    >
      <div style={{height: '100vh'}}>
        some content
      </div>
    </Modal>

and this is how it looks like

enter image description here

i want it to look like this

enter image description here

like image 365
Faizan Ahmad Avatar asked Oct 19 '25 11:10

Faizan Ahmad


1 Answers

With pure JavaScript you can do something like

const modal = document.querySelector('#myModalsClass')
modal.requestFullscreen()

If you look up the docs for the fullscreen API you will find other useful information about how to work with this.

If you're using React you need to use a ref to access the dom api

import React, { useRef } from "react";

const MyComponent = (props) => {
  const myFullscreenComponent = useRef();
  const openContentFullscreen = () => {
    const element = myFullscreenComponent.current;
    if (element && element.requestFullscreen) {
      element.requestFullscreen();
    }
  };
  return (
    <div>
      <button onClick={openContentFullscreen}>Full Screen</button>
      <div className="modal" ref={myFullscreenComponent}>
        content I want to be fullscreen
      </div>
    </div>
  );
};
like image 141
alexandercannon Avatar answered Oct 21 '25 01:10

alexandercannon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!