HTML5 video: possible to place regular html content over video

后端 未结 4 1413
星月不相逢
星月不相逢 2021-01-02 07:35

Just wondering if anyone knows any tricks to getting regular html content (mainly an img tag) to display on top of a video (via the video tag)?

相关标签:
4条回答
  • 2021-01-02 08:19

    Why not use the poster attribute? That way you can display an image until the video is loaded or play.

    0 讨论(0)
  • 2021-01-02 08:31

    You can simply put html elements on top of HTML5 video by positioning them absolutly on top of the video. Give both the video element and the HTML element a "position:absolute" and put the HTML element a z-index higher than the video element's.

    0 讨论(0)
  • 2021-01-02 08:33

    Can you set the video as background for that div? Not sure if it would work for your layout, but it seems logical...

    0 讨论(0)
  • 2021-01-02 08:38

    As others have intimated it's very easy to position HTML elements on top of VIDEO elements using absolute positioning. The challenge comes when you try to capture events on them in the iPhone, iPod and possibly older Android phones that don't play video assets inline on the page (as opposed to in a thin native playback client) since in those instances the VIDEO element greedily captures events.

    If you use an IMAGE element or a DIV with its background-image set to an image you want to use as a "poster" or "thumbnail" then your users won't be able to tap on them to get the video to start playing -- the mobile browser will treat this behavior as if nothing but the VIDEO element exists in that space (good if you happen to click in the middle where the "big play" button is but not so helpful if you, say, have a custom control not in the middle.

    The solution I've used in the past is to just put the IMG or DIV poster on the page where you would normally put the VIDEO element and shift the VIDEO element offscreen (absolutely positioned with left style set to, say, -3000px) so it can no longer hoard those events.

    I know this isn't exactly what was asked, but hopefully this information will prove useful to someone.

    0 讨论(0)
提交回复
热议问题