嵌入 youtube 視頻響應解決方案 (embed youtube video responsive solution)


問題描述

嵌入 youtube 視頻響應解決方案 (embed youtube video responsive solution)

誰能幫幫我:

我正在嘗試製作一個 100% 寬度和響應式的嵌入 youtube 視頻,我在這個網站上找到了這段代碼來嘗試實現這一點:

http://avexdesigns.com/responsive‑youtube‑embed/

css:

.video‑container {
    position: relative;
    padding‑bottom: 56.25%;
    padding‑top: 30px; height: 0; overflow: hidden;
}


.video‑container iframe,
.video‑container object,
.video‑container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

Html:

<div class="video‑container">
     <iframe src="http://www.youtube.com/embed/dFVxGRekRSg" frameborder="0" width="560" height="315"></iframe>
</div>

代碼原樣:視頻甚至沒有出現:所以我將溢出隱藏在代碼中並更改“填充‑頂部”到只是“頂部”:將視頻向下推:視頻在我的頁面頂部,它應該在下面寫著“為什麼是凱文庫爾布斯室內設計/觀看下面的視頻?”

為了部分獲取我希望它顯示的視頻,我從我的 html 中刪除並相應地調整 iframe:

iframe { 
    width: 100%;
    top: 5px;  
    margin‑bottom: ‑5px
}

視頻代碼來自 288‑304

http://graph‑art.matc.edu/harrisd5/vicom126/a2/index.html

這樣做只是讓 youtube 縮略圖封面照片在播放視頻時做出響應,它是中心。那麼我如何讓這個視頻具有 100% 的寬度和響應性,同時保持其縱橫比置於“為什麼選擇 Kevin Kurbs 內部欄?”下方。?

那麼我如何讓這個視頻具有 100% 的寬度和響應性,同時保持其縱橫比置於“為什麼選擇 Kevin Kurbs 內部欄?”下方。?

那麼我如何讓這個視頻具有 100% 的寬度和響應性,同時保持其縱橫比置於“為什麼選擇 Kevin Kurbs 內部欄?”下方。?


參考解法

方法 1:

Here is the solution I found:

HTML:

<div class='embed‑container'>
    <iframe src='https://www.youtube.com/embed/QILiHiTD3uc' frameborder='0' allowfullscreen></iframe>
</div>

CSS:

.embed‑container {
    position: relative;
    padding‑bottom: 56.25%;
    height: 0;
    overflow: hidden;
    max‑width: 100%;
}

.embed‑container iframe, .embed‑container object, .embed‑container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

方法 2:

In this case you could use calculated height for your iframe. It is calculating from the page width and the default aspect ratio of the youtube video iframe.

iframe {
    width: 100%;
    top: 5px;
    margin‑bottom: ‑5px;
    height: calc(100vw*(315/560));
}

方法 3:

When I've done responsive videos before, I've used this bit of jQuery. When the screen is resized, it calculates what the height should be.

<script>    
var $allVideos = $("iframe[src^='https://player.vimeo.com'], iframe[src^='http://player.vimeo.com'], iframe[src^='https://www.youtube.com'], iframe[src^='http://www.youtube.com'], object, embed"),


    $allVideos.each(function() {

      $(this)
        // jQuery .data does not work on object/embed elements
        .attr('data‑aspectRatio', this.height / this.width)
        .removeAttr('height')
        .removeAttr('width');

    });

    $(window).resize(function() {



      $allVideos.each(function() {

        $fluidEl = $(this).parent();
        var newWidth = $fluidEl.width();

        var $el = $(this);
        $el
            .width(newWidth)
            .height(newWidth * $el.attr('data‑aspectRatio'));

      });

    }).resize();
</script>

方法 4:

Here is the CSS code:

.yt‑container {
  position:relative;
  padding‑bottom:56.25%;
  padding‑top:30px;
  height:0;
  overflow:hidden;
}
.yt‑container iframe, .yt‑container object, .yt‑container embed {
  position:absolute;
  top:0;
  left:0;
  width:100%;
  height:100%;
}

And below is the HTML code:

<div class="yt‑container">
   <iframe src="https://www.youtube.com/embed/hfQdkBOxXTc" frameborder="0" allowfullscreen></iframe>
</div>

Source: Make YouTube Embed Video Responsive Using CSS

(by MidnitezorroJulienRiouxMate ZaboOli BFaruque Ahamed Mollick)

參考文件

  1. embed youtube video responsive solution (CC BY‑SA 2.5/3.0/4.0)

#video #css #youtube #html






相關問題

當前在網站上放置音頻和視頻的最佳方式是什麼? (what's the current best way to put audio and video on a web site?)

相當於PNG的視頻? (Video equivalent of PNG?)

IOS - UISaveVideoAtPathToSavedPhotosAlbum 如何返回保存的視頻路徑? (IOS -how could UISaveVideoAtPathToSavedPhotosAlbum return the saved video path?)

如何使用 c# 編寫一個簡單的視頻播放器,以準確的 fps 播放視頻? (How to use c# to write a simple video player which plays the video with accurate fps?)

Monotouch - MoviePlayer 永遠不會超越“正在加載...” (Monotouch - MoviePlayer never gets beyond "loading...")

Android MediaMetadataRetriever setDataSource 失敗 (Android MediaMetadataRetriever setDataSource failed)

枚舉Windows上所有可用視頻編解碼器的最佳方法? (Best way to enumerate all available video codecs on Windows?)

如何通過上傳單個視頻文件為任何 html5 視頻獲得多種質量(360p、480p、720p)選擇 (how can i get multiple quality(360p,480p, 720p) selection for any html5 video with uploading single video file)

由於不支持的編解碼器,FFmpeg/Avconv 無法複製字幕? (FFmpeg/Avconv unable to copy subtitles due to unsupported codec?)

嵌入 youtube 視頻響應解決方案 (embed youtube video responsive solution)

如何輕鬆識別流是視頻還是圖片【ffmpeg庫】 (How to easily recognize whether stream is video or image [ffmpeg library])

livestream.com 如何顯示存檔的視頻? (how is livestream.com displaying the archived video(s)?)







留言討論