LoginSignup
0
0

More than 1 year has passed since last update.

JS Youtube 埋め込み レスポンシブ

Posted at
src.html
<div class="movie">
  <iframe src="https://www.youtube.com/embed/xxxxxx" allowfullscreen></iframe>
</div>
script.js
$(()=>{
    const bw = document.body.scrollWidth;
    // 表示幅700以上の場合のみ
    if(bw > 700) {
        // 横:コンテンツ幅の80%、縦:横の9/16サイズ
        const w = $('.movie')[0].clientWidth;
        $('iframe').attr('width', w * 0.8);
        $('iframe').attr('height', w * 0.8 * 9 /16);
    }
});
0
0
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
0
0