How do I draw a shape on an HTML5 video using SVG?

后端 未结 2 477
予麋鹿
予麋鹿 2021-01-14 18:06

I am trying to draw shapes on top of an HTML5 video, but am having trouble figuring out how to do it. I know how to apply a mask on top of the video:



        
相关标签:
2条回答
  • 2021-01-14 18:49

    yes, css solution is one option. try to put those two elements above either in one div or (as jörn pointed out) with absolute positioning. z-index is very useful, to make sure your svg is really on top.

    <div id="canvas">
        <video id="videoContainer"> (...) </video>
    
        <svg id="svgContainer"> (...) </svg>
    </div>
    
    
    <style> 
       canvas{ position:relative; width:480px; height:240px; }
       videoContainer{ position:relative; width:100%; height:100%; z-index:1 }
       svgContainer{ position:relative; width:100%; height:100%; z-index:2 }
    </style>
    
    0 讨论(0)
  • 2021-01-14 18:55

    use CSS position:absolute to position your SVG where you want it.

    <style> svg { position:absolute; top:20px; left:40px; }</style>
    

    the above example should positions the svg 20 px from the top of the page and 40px from the left

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