css - jQuery Overlay Image on HTML5 Video -


i trying build small utility can start watching html5 video (not youtube - stream same server site hosted on), click in specific area of video, have pause , put small circle on video clicked. once occurs, small window pop user can comment indicating why clicked there (something wrong in video, etc.).

the basic html structure this:

<div id="videocontainer" style="margin-left: auto; margin-right: auto; height: 550px; width: 950px; background-color: #fff">        	      <video id="pcvideo" src="fvb0375.mov" style="margin-left: auto; margin-right: auto; height: 550px; width: 950px; display:inline;" preload="auto" controls></video>  </div>

the custom styling can ignored - center video on screen generic height/width won't used later. js on page (to handle when video clicked) this:

$("#pcvideo").click(function(e) {      //height , width of container    var height = $("#pcvideo").height();    var width = $("#pcvideo").width();      //get click position inside container    var relativex = e.pagex - this.offsetleft;    var relativey = e.pagey - this.offsettop;      //overlay    var overlay = $("<div height='75' width='75' class='overlay'/>");    overlay.offset({      top: relativey,      left: relativex    });    var circle = $("<img/>");    circle.attr('src', 'circle.png');    overlay.append(circle);      $("#videocontainer").append(overlay);      video.pause();  });

as stands, video pauses fine, image shows below video. if hide video, image pops in right supposed to, i've realized is applying correctly, reason video considered block-level element, in realm gets bumped "next line" were, throwing positioning off, so:

video shown, circle below container: video image showing underneath

video hidden, circle shows in appropriate spot: hidden video, image shows in correct spot

i've tried z-index css, tried absolute/relative positioning , nothing seems work thing on top of video.

any ideas?

check out fiddle.

i have used sample video , sample circular image testing purpose.

initially image hidden.

when click on video, image appears @ position click done , video pauses.

i hope helps.

here snippet.

$("#vid").click(function(e) {      //height , width of container    var height = $("#pcvideo").height();    var width = $("#pcvideo").width();      //get click position inside container    var relativex = e.pagex - this.offsetleft;    var relativey = e.pagey - this.offsettop;      $('#image').css(      "left", relativex - 25);    $('#image').css(      "top", relativey - 25);    $('#image').show();    //overlay    var video = document.getelementbyid('vid');      video.pause();  });
#image {    position: absolute;    display: none;  }  #vid {    position: absolute;  }  div {    width: 100%;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  <div id="container">    <video id="vid" src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" width="500" heigh="400" preload="auto" controls></video>    <img id="image" src="http://www.gritengine.com/luaimg/circle.png" />  </div>


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -