javascript - Make a div's size and position the same as a video's -
i have html5 video width of 100% , height of 100% , , want wrap div fit size , position of video (not video tag, video itself) using necesary.
html:
<div id="wrapper"></div> <video id="vid" controls preload="none" width="100%" height="100%" poster="http://video-js.zencoder.com/oceans-clip.png"> <source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4'/> <source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'/> <source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg'/> </video>
css:
#wrapper{ width: 2px; height: 2px; border: solid 2px red; position: absolute; }
js (jquery):
setinterval(function(){ $("#vid").height($(window).height() - $("header").height() - 7); /*there header , bunch of other stuff in original code*/ }, 10);
this first question here if need i'll glad answer. thanks.
edit: need this
calculation of height , width of video using video's aspect ratio seems necessary. fiddle puts height on video element (set 264), not same question's code sample. more appropriate question?
that being said, perhaps can attempt calculate proper height , top css value of wrapper, assuming video width landscape (full window width):
javascript:
var vidratio = $("#vid").height()/$("#vid").width(); setinterval(function(){ $("#vid").height($(window).height() - $("header").height() - 7); var width = $(window).width()-20; // abitrary 20 pixels account border/margin/padding? $("#wrapper").css({ 'width': width, 'height':width*vidratio, 'top':($(window).height()-width*vidratio)/2 }); /*there header , bunch of other stuff in original code*/ }, 10);
css:
#wrapper { width: 2px; height: 2px; border: solid 2px red; position:absolute; }
http://jsfiddle.net/lsubirana/1ly0f5cx/
it's not perfect may help.
Comments
Post a Comment