简体   繁体   English

HTML5:在带有控件的视频上放置画布

[英]HTML5: Placing a canvas on a video with controls

I want to draw things on HTML5 video. 我想在HTML5视频上绘制内容。 For that I am trying to place a canvas on the HTML5 video element. 为此,我试图在HTML5视频元素上放置画布。

But there is a problem when I place the canvas on the video element the video controls do not work. 但是当我将画布放在视频元素上时视频控件不起作用时会出现问题。 Since canvas getting all the mouseover and click events. 由于canvas获得了所有鼠标悬停和点击事件。 Is there a way to delegate the events to video controls or show the controls in somewhere else? 有没有办法将事件委托给视频控件或在其他地方显示控件?

Any help/idea would be great. 任何帮助/想法都会很棒。

What you should do is implement your own controls (or use an existing set such as videojs ) 你应该做的是实现你自己的控件(或使用现有的集合,如videojs
You can read my answer to this question: Html5 video overlay architecture 您可以阅读我对这个问题的回答: Html5视频叠加架构

You can capture the click events in the canvas and calculate their position. 您可以捕获画布中的单击事件并计算其位置。 Based on that, you could approximate which control was targeted and make the video changes your self. 在此基础上,您可以估算出哪个控件被定位,并使视频改变您的自我。
I mean something like this : 我的意思是这样的:

canvas.onclick = function(e){
    if(isOverPauseBtn(e))
        video.pause();
    //.. and so on
}

Increase the z-index of canvas. 增加画布的z-index。 z-index=10 Bring the video under the canvas. z-index=10将视频置于画布下。 Height of canvas = height of entire video - height of video controls. 画布高度=整个视频的高度 - 视频控件的高度。

You can cover only the video part with canvas and if hover on the bottom of the canvas, you will get the controls 您只能使用画布覆盖视频部分,如果将​​鼠标悬停在画布底部,您将获得控件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM