Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set width and expect proportional auto height, nor vice versa #201

Open
ronenmagid opened this issue Aug 19, 2019 · 7 comments
Open

Comments

@ronenmagid
Copy link

This component forces pre-knowledge of the exact video size or it cannot work.

I have a 500px width available for it, but specifying 500px width alone gives you a very short height, that's completely non-proportional to the width.

@ndom91
Copy link

ndom91 commented Aug 23, 2019

@ronenmagid whats the problem with also setting the height beforehand?

A youtube video is always 16:9, so if you have 500px width available for it, just specify a height of 281px

@MichaelDimmitt
Copy link

@ronenmagid
The Iframe that the project uses has an id called widget2

Add this change to your css file. 🙂

#widget2{
  height: 100vh
  width: 100vw
}

Or however you want to set the height and width dimensions for mobile responsiveness.

Kind of a hack but it gets the job done.

@MichaelDimmitt
Copy link

Turns out the widgets were dynamic.
So when javascript was generating a new iframe it would increment the widget id.

to get around this I put the styling on iframe as a whole.
Understanding this is not a good solution if you have more than one iframe on a page.

iframe{
  height: 100vh;
  width: 100wv;
}

@MichaelDimmitt
Copy link

Really the component should accept styles as props to be added to the parent div and the iframe. 🤷‍♂️

@ruisaraiva19
Copy link
Collaborator

@MichaelDimmitt you can check out this comment with a solution for making the iframe responsive.

@MichaelDimmitt
Copy link

@ronenmagid , consider looking at #242 as ruisaraiva19 mentioned
#242

@rekliner
Copy link

rekliner commented Feb 2, 2023

another solution that works well enough but not ideal since the size will bounce:
width can be set to 100% and responds to container size.
when the onReady event fires check getSize(), which is part of the YouTube API but undocumented.
Use the width from getSize to calculate width for 16:9 and send it to setSize()

<YouTube
   onReady={(e) => {
      const { width, height } = e.target.getSize();
      e.target.setSize(width, width / 16 * 9)
  }
...
/>

Unfortunately getSize is not officially in the Youtube iframe API so its not in the type definitions...but it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants