将视频带到特定时间的 html5 视频按钮 [英] html5 video button that takes video to specific time
问题描述
我正在尝试放置一个无需控件即可自动播放的视频,但我想在视频下方添加三个自定义按钮,每个按钮将视频跳转到特定时间.不使用 Youtube、Vimeo 或任何其他托管视频.我已经能够链接到特定时间,但这会打开一个新窗口并且与跨浏览器不兼容.这可能吗?
I'm trying to place a video that autoplays without controls but I want to add three custom buttons below the video, each button jumps the video to a specific time. Not using Youtube, Vimeo or any other hosted video. I've been able to link to a specific time, but that opens a new window and isn't cross browser compatible. Is this possible?
<video id="movie" style="border:none;" width="575" height="240" preload autoplay controls>
<source src="video.ogv" type="video/ogg; codecs=theora,vorbis" />
<source src="video.mp4" type="video/mp4; codecs=avc1.42E01E,mp4a.40.2" />
<source src="video.webm" type="video/webm; codecs=vp8,vorbis" />
</video>
<p class="navBtns">
<a href="video.ogv#t=9" target="_blank"><img src="dot.png" /></a>
<a href="video.ogv#t=17" target="_blank"><img src="dot.png" /></a>
<a href="video.ogv#t=29" target="_blank"><img src="dot.png" /></a>
</p>
<script>
var v = document.getElementsByTagName('video')[0];
v.removeAttribute('controls') // '' in Chrome, "true" in FF9 (string)
v.controls // true
</script>
推荐答案
您的链接有两个不同的问题:
Your links feature two different problems:
- 它们具有 target="_blank" 属性,因此它们会打开一个新窗口/选项卡.(摆脱那些)
- 您要链接到视频本身,而不是链接到嵌入视频的页面.这不会按预期工作.
要在不离开页面的情况下直接控制页面上的视频,您需要一些 javascript.在这里,您将找到一个如何工作的示例.
To control a video on a page directly without leaving the page, you'll need some javascript. Here you'll find an example how this will work.
您需要一个函数来跳转到点击您的一个链接的特定时间,例如(例如):
You'll need a function to jump to the specific time on click of one of your links, that would be (for instance):
var firstlink = document.getElementByTagName('a')[0];
firstlink.addEventListener("click", function (event) {
event.preventDefault();
myvideo.currentTime = 7;
myvideo.play();
}, false);
这篇关于将视频带到特定时间的 html5 视频按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!