2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ReactでYoutubeの埋め込みをするときにレスポンシブに対応したい

Last updated at Posted at 2024-01-04

はじめに

Youtubeの埋め込みをしたのですが、レスポンシブに対応するのに困ったのでまとめていきます。

問題

react-playerreact-youtubeのどちらかを使って、
モバイルのときは指定した高さと幅
それ以外は幅を100%

という条件にしたかったのですが、なぜか大きさが変わらなかったり、大きさは変わるがプレイヤーの中は変わらない現象が起きました

image.png

解決方法

結果的にはreact-playerのwidthとheightを指定することで解決しました (classNameで調節していたのでだめでした)

        <ReactPlayer
          url={videoUrl}
          className="md:hidden"
          width={"343px"}
          height={"192px"}
        />
        <ReactPlayer url={videoUrl} className="hidden md:block" />

おわりに

なんとか解決できたので壁は超えた感じがしました

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?