【问题标题】:Youtube video as background on landing pageYoutube 视频作为登陆页面的背景
【发布时间】:2016-10-14 21:13:26
【问题描述】:

我想在我的着陆页上使用 youtube 视频序列作为背景。 我希望视频静音并只使用一分钟。这是一个现有的 youtube 视频(来自朋友)。

  • 我怎样才能让它响应? (当我调整大小时使用 youtube,我有大的黑色边框)

  • 如何静音和循环播放?

我相信我需要一些 JS……但我对 JS 什么都不懂……如果有人能解释一下。

.video-background
  iframe src="https://www.youtube.com/embed/iUBn-nipNkk?rel=0&controls=0&showinfo=0;start=245&autoplay=1&&loop=1" frameborder="0"

.container.main-title
    .row
      .col-xs-12.col-sm-12.col-md-12.text-center
        h1.text-inverse
          | Mark Knopfler
        p.text-inverse
          | Mark in summer long ago
        br
        br
        =link_to root_path(@root, anchor: "about") do
          i.fa.fa-4x.fa-arrow-down.fa-fw.hub.text-inverse

.section
  .container
    .row
      .col-xs-12.col-sm-6.col-md-5
        =image_tag("mains/band.png", class:'band')
      .col-xs-12.col-sm-6.col-md-7#about
        br
        h2.text-primary  About the website
        p.site-description "Mark In Summer Long AgoVestibulum fringilla pede sit amet augue. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Praesent egestas tristique nibh. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem."

.section
  .container
    .col-xs-12.col-sm-12.col-md-12
      h1.text-center.text-primary MK & me... somehow...
      br
    .row
      .col-xs-12.col-sm-4.col-md-4.under-section
        .make-it-slow
          = link_to page_path('concerts/index') do
            .thumbnail
              = image_tag("mains/concerts.jpg", class:"category")
              h3.section-title Concerts
      .col-xs-12.col-sm-4.col-md-4.under-section
        .make-it-slow
          = link_to page_path('calendars/index') do
            .thumbnail
              = image_tag("mains/calendars.jpg", class:"category")
              h3.section-title Calendars
      .col-xs-12.col-sm-4.col-md-4.under-section
        .make-it-slow
          = link_to page_path("events/index") do
            .thumbnail
              = image_tag("mains/events.jpg", class:"category")
              h3.section-title Other events

.section
  .container
    .col-md-12
      h1.text-center.text-primary Related Mark Knopfler websites
      br
    .row
      .col-xs-12.col-sm-4.col-md-4.under-section
        .make-it-slow
          = link_to "http://www.markknopfler.com/" do
            .thumbnail
              = image_tag("mains/mkcom.jpg", class:"category")
              h3.section-title Official MK Website
              p.section-description MK.com
              p.section-description Visit the very official MK website, tour dates, shop, annoucements...

      .col-xs-12.col-sm-4.col-md-4.under-section
        .make-it-slow
          =link_to  "http://www.guyfletcher.co.uk/"  do
            .thumbnail
              = image_tag("mains/gf.jpg", class:"category")
              h3.section-title Guy Fletcher 
              p.section-description A very intersting Website to keep in your favorites.
              p.section-description Guy Fletcher runs here a forum, studio and tour diaries ! Have a look !

      .col-xs-12.col-sm-4.col-md-4.under-section
        .make-it-slow
          = link_to "http://www.amarkintime.org/forum/" do
            .thumbnail
              = image_tag("mains/forum.jpg", class:"category")
              h3.section-title AMIT forum
              p.section-description A very nice place to exchange with fans from all over the world! This a non official forum. 
              p.section-description Be cool and do not moan !

有点粗鲁

.video-background iframe
  position: absolute
  top: 0
  left: 0
  width: 100%
  height: 100%
  pointer-events: none
  filter: grayscale(80%)
  z-index: -99

.main-title
  margin-top: 15%
  height: 80%
  color: #ffffff
  h1
    font-size: 60px
  p
    font-size: 30px

【问题讨论】:

  • 您的网站上没有视频,也没有 iframe。在您的 application.js 清单中,它具有 jQuery 和 Bootstrap 插件。然而,您添加了另一个要加载的 jQuery 和 Bootstrap 副本。您在样式表之前加载了脚本。您在正文中有<link>s,在正文的顶部区域有一个<script>。在这个<script> 块中,它试图为一个不存在的元素启动一个轮播插件。顺便说一句,您有一个 <script> 标签拼写错误为 <scrip>
  • 目前还没有视频我知道。我放了我当前网站的例子来显示我想在哪里添加视频(而不是面包车图像)......我会检查脚本谢谢
  • 在这里查看我的 iFrameless/JS/CSS 唯一解决方案stackoverflow.com/questions/41616179/…

标签: javascript html css ruby-on-rails-4 youtube


【解决方案1】:

您提供的代码与您想在 YouTube 上做什么几乎没有关系(.video-background 是个例外)。请先在包含您的视频的网页上测试此代码段,并且先不使用所有其他内容。尝试在源中找到实际的 YT 播放器,并注意剪切的内容和粘贴的位置。

片段

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1, user-scalable=no">
  <title>YouTube FS/Mute</title>

  <style>
    .frame {
      position: fixed;
      z-index: -1;
      width: 100%;
      height: 100%
    }
  </style>
</head>

<body>
  <header></header>
  <section class="frame">
    <iframe id='player' src="https://www.youtube.com/embed/o0u4M6vppCI?&enablejsapi=1" frameborder="0" allowfullscreen height="100%" width="100%"></iframe>

  </section>
  <footer>&nbsp;</footer>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <script src="http://www.youtube.com/player_api"></script>


  <script>
    var player;

    function onYouTubePlayerAPIReady() {
      player = new YT.Player('player', {
        playerVars: {
          'autoplay': 1,
          'controls': 0,
          'autohide': 1,
          'wmode': 'opaque',
          'showinfo': 0,
          'loop': 1,
          'mute': 1
        },
        videoId: 'o0u4M6vppCI',
        events: {
          'onReady': onPlayerReady
        }
      });

    }

    function onPlayerReady(event) {
      event.target.mute()
    }
  </script>
</body>

</html>

【讨论】:

  • 对不起,它没有达到我想要的效果...看看我的编辑,我相信我不够清楚
【解决方案2】:

你可以尝试做一个完整的后台 iframe 生活:

<iframe id="myVideo" src="https://www.youtube.com/embed/myvideo;autoplay=1" width="100%" height="100%" frameborder="0" allowfullscreen></iframe>
  1. 100% 的背景应使其具有响应性。
  2. 要使声音静音,您需要一些 JavaScript。 'autoplay=1' 将使其自动播放和循环播放。

创建一个 js 文件并添加这个 jQuery 位:

var myVideo =  iframe.getElementById('myVideo'); 
myVideo.mute();

用您在 iframe 上选择的 id 更改“myVideo”。

希望这会有所帮助。

【讨论】:

  • 我在我的 appication.js 中添加了 JQuery 位,并将 id 添加到我的 ifram 中,就像iframe#myVideo src="https://www.youtube.com/embed/iUBn-nipNkk?rel=0&amp;amp;controls=0&amp;amp;showinfo=0;start=245&amp;amp;autoplay=1&amp;amp;&amp;loop=1" frameborder="0" height="100%" width="100%" 它很苗条而不是 html 顺便说一句,它不会改变任何东西:(跨度>
【解决方案3】:

也许这会有所帮助,而且它实际上比尝试 youtube 更快...

我放弃了 youtube 视频,因为我无法删除黑色边框,这真的很烦人。 所以我已经下载了视频,在 iMovie 中剪切了我需要的序列,静音并将视频上传到 AWS。

我这样做了:

.cover
  =video_tag(["https://s3-eu-west-1.amazonaws.com/markinsum/MKlanding.mp4"], autoplay:true, loop:true, class:"landing-video")

还有我的 Sass:

.landing-video
  position: absolute
  top: 50%
  left: 50%
  transform: translate(-50%, -50%)
  filter: grayscale(80%)
  z-index: 1
  min-width: 100%
  min-height: 100%

结果是here,顺便说一句,有待改进

【讨论】:

    猜你喜欢
    • 2017-09-27
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2014-12-22
    • 2019-12-18
    • 1970-01-01
    • 2015-02-14
    • 2019-03-24
    相关资源
    最近更新 更多