【问题标题】:How can I present information on top of a full screened youtube video embedded on my webpage?如何在嵌入我网页的全屏 youtube 视频上显示信息?
【发布时间】:2013-03-25 20:05:59
【问题描述】:

我正在开发一个网络应用程序,其中我的一个网页中嵌入了一个 youtube 视频播放器。我正在尝试在播放视频的顶部(全屏)显示额外信息。额外信息是指带有一些文本或图像的消息。 嵌入式播放器的代码类似这样:

<div id="player" align="center"></div>

  <noscript>This feature requires Javascript, please turn it on</noscript>

  <script>
    // 2. This code loads the IFrame Player API code asynchronously.
    var tag = document.createElement('script');

    var uid;
    var firstStatus = 1;
    var firstTimeStamp = 0;
    // Current state of the player
    var state = -1;

    tag.src = "//www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    // 3. This function creates an <iframe> (and YouTube player)
    //    after the API code downloads.
    var player;
    var show = getVarsFromUrl()['showId'];
    function onYouTubeIframeAPIReady() {
      player = new YT.Player('player', {
        height: '390',
        width: '640',
        videoId: show,//'a8u_a9q978M',//'u1zgFlCw8Aw',
        events: {
          'onReady': onPlayerReady,
          'onStateChange': onPlayerStateChange
        }
      });
    }

我打算在正在播放的视频上展示额外的信息。 我希望我足够清楚。谢谢!

额外代码: 样式(CSS):

<style>
  body {
    padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
    background-color: #222222;
    color: #C0C0C0;
  }
  img {
    position:relative;
    left:500px;
    top:500px;
    z-index:5;
  }
  iframe {
    position:absolute;
    left:500px;
    top:500px;
    z-index:-1;
  }
</style>

还有图片:

<img src="smiley.png" alt="Smiley face" height="42" width="42">

【问题讨论】:

    标签: javascript html youtube-javascript-api


    【解决方案1】:

    在网址末尾添加?wmode=opaque,以启用z-index。然后在你的 CSS 中使用 z-index 来相应地分层你的样式。

    【讨论】:

    • 它不起作用。全屏的 youtube 视频涵盖了我显示的任何图像,即使 z-index 值很高。 img { position:absolute; left:500px; top:500px; z-index:5; }
    • 您必须为我发布更多代码 (css/html) 才能提供更多帮助。
    • 我刚刚发布了 CSS 代码和 img。整个页面很大,但如果您需要其他内容,请告诉我。顺便说一句,谢谢你的帮助!
    • 图像出现在 youtube 播放器的顶部,直到我进入全屏时图像一起消失。在其他地方有人说当你进入全屏时,一个新的 Flash 播放器窗口是打开的,因此它不可能在上面显示任何东西。不可能是这样的,我相信有办法做到这一点。
    猜你喜欢
    • 2012-02-17
    • 1970-01-01
    • 2019-08-14
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多