javascript - 视频标签上的居中图像

标签 javascript html css video

好吧,对于一个元素,我需要在运行时根据 UserAgent 在视频顶部呈现居中图像(播放按钮)。如果 userAgent 不是 Firefox,我想显示图像,因为 Firefox 在开始时有自己的 playEvent 和视频顶部的按钮。我之前的所有尝试都失败了。

我试过:

  • 在video标签中添加z-index为10,视频z-index为1
  • 在视频标签周围放置一个带有背景图片的 div

有没有其他方法可以做到这一点,请不要使用海报回复,因为我已经有我需要使用的海报。

-编辑-

代码:

<tr>
    <td runat="server" width="680px" height="383px" id="vContainer">
        <video id="player" style="z-index: 1" width="100%" height="100%" title="" controls runat="server">
            <source runat="server" id="ffVideo" type="video/ogg" />
            <source runat="server" id="mp4Video" type="video/mp4" />
        </video>
        <embed id="playerOld" width="680px" autostart="false" allowfullscreen="true" height="383px" title="" style="display: none" type="application/mp4" runat="server" />
    </td>
</tr>

最佳答案

就像放一个标签并给它更多的 z-index 一样简单。你可以让它运行:http://jsfiddle.net/65rda3jq/

<div class="cont">
    <div class="img"></div>
     <video id="player" style="z-index: 1" width="100%" height="100%" title="" controls
        runat="server">
        <source runat="server" id="ffVideo" type="video/ogg" />
        <source runat="server" id="mp4Video" type="video/mp4" />
      </video>
      <embed id="playerOld" width="680px" autostart="false" allowfullscreen="true" height="383px"
        title="" style="display: none" type="application/mp4" runat="server" />
</div>

CSS

.cont {
    position:relative;
}

video { position: relative; }
.img {z-index:10; background: #f00; position: absolute; top: 50%; left: 50%; width: 50px; height: 50px; }

关于javascript - 视频标签上的居中图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32095916/

相关文章:

javascript - 不应用或覆盖外部 CSS

html - Twitter-bootstrap row-fluid up to span12 only

javascript - Bootstrap 两列布局和 ng-repeat (angularjs)

html - 在中心显示幻灯片 div

c# - 使用 asp.net(C#) 更改 div 标签中的 css 类

javascript - 单击大图时图像不会加载

javascript - Jquery - Carasol 构建完成并希望获得有关最佳实践/整理我的代码的建议

javascript - Uncaught ReferenceError : Lawnchair is not defined

html - CSS 布局 div 位于下方和圆 table 行

javascript - JS 循环每 3 个循环递增,但第一个数字增加 1