markdown 流体宽度响应视频

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 流体宽度响应视频相关的知识,希望对你有一定的参考价值。

(function($) {
  $(document).ready(function() {
    var $allVideos = $("iframe[src*='//player.vimeo.com'], iframe[src*='//www.youtube.com'], object, embed"),
    $fluidEl = $("figure");

    $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() {
      var newWidth = $fluidEl.width();
      $allVideos.each(function() {
        var $el = $(this);
        $el
          .width(newWidth)
          .height(newWidth * $el.attr('data-aspectRatio'));
      });
    }).resize();
  });
})(jQuery);
Below is the (slightly adapted) script I got working on a Radicati site: 

Just enclose the oEmbed field in `<figure></figure>` tags and the video will automatically resize to fit. Ex:

```twig
<figure>
    {{ post.get_field('video') }}
</figure>
```

Make sure the javascript file is either concatenated into your main site.js or is enqueued or whatever needs to happen (depends on how your site is organized).


Note: It looks like there might be a more recent version of this fluid-video project at https://github.com/davatron5000/FitVids.js
The easiest method is if you're using Bootstrap (which we nearly always are). Bootstrap has responsive video classes built in. Setting class=“embed-responsive embed-responsive-16by9” works for YouTube videos, which are all widescreen. Also available are 4by3 (Fullscreen) and 21by9 (Cinematic Widescreen). This method is nice in that it doesn’t require javascript; it’s all css-based.

以上是关于markdown 流体宽度响应视频的主要内容,如果未能解决你的问题,请参考以下文章

scss 流体宽度视频(响应视频嵌入)

流体视频高度

流体宽度表中的响应图像(最大宽度)

使用带有响应式设计/流体宽度 CSS 的 jCrop

位置2并排流体/响应(未知宽度)

第九十五节,移动流体布局和响应式布局总结