微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将嵌入的 Twitch 视频缩放到 100% ? Check it in action on Codepen

如何解决将嵌入的 Twitch 视频缩放到 100% ? Check it in action on Codepen

我使用以下代码在使用 TailwindCSS 的 HTML 页面上嵌入 Twitch 流:

<section aria-labelledby="Live-Stream Video">
  <!-- Add a placeholder for the Twitch embed -->
  <div id="twitch-embed" phx-update="ignore"></div>

    <!-- Load the Twitch embed script -->
    <script src="https://player.twitch.tv/js/embed/v1.js"></script>

    <!-- Create a Twitch.Player object. This will render within the placeholder div -->
    <script type="text/javascript">
      new Twitch.Player("twitch-embed",{
        channel: "example",width: "100%",height: "100%",autoplay: "true"
      });
    </script>
  </div>
</section>

结果:

enter image description here

该视频未使用该视频的全部可能宽度(在 TailwindCSS 布局内)。我不知道那是多少宽度。我如何告诉 Twitch.Player 使用黑色区域边界内的任何空间?

解决方法

只需使用 css 设置生成的容器和 iframe 的样式:

#twitch-embed {
  height: 0;
  position: relative;
  overflow: hidden;
  padding: 0 0 56.25%;
  width: 100%;
  border-radius: 8px;
}

#twitch-embed iframe {
  position: absolute;
  height: 100%;
  width: 100%;
}

,

尝试使用 px 而不是 % 并尝试使用参数 allowfullscreen=true

,

使用固定值,如 "720" 等...像这样:

new Twitch.Player("twitch-embed",{
  channel: "example",width: "1280",height: "720",autoplay: "true"
});
<script src="https://player.twitch.tv/js/embed/v1.js"></script>
<section aria-labelledby="Live-Stream Video">
  <div id="twitch-embed" phx-update="ignore"></div>
</section>



? Check it in action on Codepen







版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。