【问题标题】:Vimeo full widthVimeo 全宽
【发布时间】:2017-08-09 01:13:43
【问题描述】:

我正在尝试在网页中全宽显示 vimeo 视频。

这就是现在的样子:

如您所见,黑色是全宽的,但不是视频。它应该是全宽的,没有显示控件,自动播放并循环播放。

我的代码现在看起来像这样:

<iframe src="https://player.vimeo.com/video/208176323?autoplay=1&loop=1&background=1" width="100%" height="500px" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

客户端有 vimeo plus 但没有 vimeo pro。有人可以帮我解决这个问题吗?

更新:

我已将代码更改为:

<style>
    .embed-container {
        position: relative;
        padding-bottom: 56.25%;
        height: 0; overflow: hidden;
        max-width: 100%; height: auto;
    }
    .embed-container iframe, .embed-container object, .embed-container embed {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
</style>

<div class='embed-container'><iframe src='https://player.vimeo.com/video/208791851?autoplay=1&loop=1&background=1' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>

但我的底部和顶部仍然有黑色边框。

我创建了一个 jsfiddle,您也可以在其中看到:https://jsfiddle.net/07fkfwz3/。而且here看到的视频是没有边框的。

【问题讨论】:

    标签: html css video width vimeo


    【解决方案1】:

    您为容器创建的魔法填充数字需要与视频的纵横比相匹配。如果您在 vimeo 上查看视频,则分辨率为 1296x540。要获得纵横比百分比,除以 540 / 1296 * 100% = 41.66666667% 内边距。

    这是一个小提琴,因为视频似乎在 SO 沙盒中播放效果不佳。 https://jsfiddle.net/mcoker/p7q6x4d5/1/

    .embed-container {
      --video--width: 1296;
      --video--height: 540;
    
      position: relative;
      padding-bottom: calc(var(--video--height) / var(--video--width) * 100%); /* 41.66666667% */
      overflow: hidden;
      max-width: 100%;
      background: black;
    }
    
    .embed-container iframe,
    .embed-container object,
    .embed-container embed {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }
    <div class='embed-container'>
      <iframe src='https://player.vimeo.com/video/208791851?autoplay=1&loop=1&background=1' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
    </div>

    【讨论】:

    • 在小提琴中添加body { margin:0 } 进一步体现了最完整的宽度:)
    • 以上,你的意思是padding-bottom: padding-bottom: 41.66666667%;,对吧?您在 JS Fiddle 代码中有这种方式,但在 SO 沙箱代码中没有。
    • @tanius 是的,感谢您发现这一点。清理它并添加 css 自定义属性和 calc() 为您做数学。
    【解决方案2】:

    试试这个

    <style>
    .embed-container { 
        position: relative; 
        padding-bottom: 56.25%; 
        height: 0; overflow: hidden; 
        max-width: 100%; height: auto; 
    } 
    .embed-container iframe, .embed-container object, .embed-container embed { 
       position: absolute; 
       top: 0; 
       left: 0; 
       width: 100%; 
       height: 100%; 
    }
    </style>
    
    <div class='embed-container'><iframe src='https://player.vimeo.com/video/208176323?autoplay=1&loop=1&background=1' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>
    

    编辑

    所以在我看到小提琴之后,我设法解决了你的问题:

    CSS

            .embed-container {
          position: relative;
          padding-bottom: 56.25%;
    
          height: 0;
          overflow: hidden;
          max-width: 100%;
          height: auto;
        }
    
        .embed-container iframe,
        .embed-container object,
        .embed-container embed {
          position: absolute;
          top: 13%;
          width: 100%;
          height: 75%;
        }
    

    HTML

    <div class='embed-container'>
      <iframe src='https://player.vimeo.com/video/208791851?autoplay=1&loop=1&background=1' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
    </div>
    

    【讨论】:

    • 我试过这个。但是我的顶部和底部仍然有黑色边框(更新了我的主题)。
    • je css 中可能存在冲突?
    • 我已经用一个 jsfiddle 更新了我的主题,你也可以在其中看到这个。
    • 将 padding-bottom 值更改为 42% 是否足以满足您的需求?还要感谢@VC.One 让这个评论成为可能。
    【解决方案3】:

    替换视频的ID号(本例为19022044)

    HTML:

    <div class="vimeo-full-width">
       <iframe src="https://player.vimeo.com/video/19022044?title=0&byline=0&portrait=0" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
    </div>  
    

    CSS:

    .vimeo-full-width {
        padding: 56.25% 0 0 0;
        position: relative;
    }
    
    .vimeo-full-width iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
    

    由于纵横比为 16:9,顶部内边距为 56.25%

    【讨论】:

    • 谢谢谢谢谢谢!!!
    【解决方案4】:

    你可以试试这个: https://jsfiddle.net/c4j73z16/4/

    html

    <div class='embed-container'>
      <div class="vcontent">
      <iframe src="https://player.vimeo.com/video/208176323?autoplay=1&loop=1&title=0&byline=1&portrait=1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
      </div>
    </div>
    

    css

    <style>
      .embed-container {
        position: relative;
        padding-bottom: calc(70vh - 6.7em);
        height: 0;
        overflow: hidden;
        max-width: 100%;
      }
    
      .embed-container .vcontent {
        position: absolute;
        overflow: hidden;
        height: calc(70vh - 6.2em);
        width: 100%;
        margin-top: -0.5em;
      }
    
      .embed-container iframe,
      .embed-container object,
      .embed-container embed {
        position: absolute;
        overflow: hidden;
        top: 0;
        left: 0;
        width: 100%;
        height: 70vh;
        padding: 0;
        margin: -3em 0;
      }
    </style>
    

    我使用vh 高度和另一个div.vcontent,以正确移动以更好地满足您的需求。

    【讨论】:

      【解决方案5】:

      HTML 是

      <div class='container'>
        <div class="vcontent">
        <iframe src="https://player.vimeo.com/video/208791851?autoplay=1&loop=1&background=1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
        </div>
      </div>
      

      在造型方面

      .container {
            position: relative;
            padding-bottom: calc(70vh - 6.7em);
            height: 0;
            overflow: hidden;
            max-width: 100%;
      
          }
          .container .vcontent {
             position: absolute;
         overflow: hidden;
         height: calc(70vh - 6.2em);
         width: 100%;
         margin-top: -0.5em;
          }
          .container iframe,
          .container object,
          .container embed {
            position: absolute;
        overflow: hidden;
            top: 0;
            left: 0;
            width: 100%;
            height: 70vh;
        padding: 0;
        margin: -3em 0;
          }
      

      【讨论】:

        【解决方案6】:

        这对我有用:

        <style>
          .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%;
          }
        </style>
        <div class='embed-container'><iframe src='https://player.vimeo.com/video/157467640?background=1' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>
        

        来源:https://forum.webflow.com/t/setting-vimeo-video-to-full-width-of-div/25499/2

        【讨论】:

          猜你喜欢
          • 2017-05-27
          • 2017-04-05
          • 2011-06-14
          • 2016-06-04
          • 1970-01-01
          • 2015-05-19
          • 2020-09-22
          • 2015-04-20
          • 2014-02-14
          相关资源
          最近更新 更多