javascript - How to copy videojs from one div into another div? -
i have div videojs in it
<div id="video"> <video id="example_video_1" class="video-js vjs-default-skin" width="200" height="200" data-setup="{}"> <source src="clip.mp4" type='video/mp4' /> </video> </div>
now i'm trying copy video div
jquery(document).ready(function(){ var video = jquery('#video').clone(true, true); jquery('#block').append( video ); });
it copies video player, doesn't work (can't play video). right way copy videojs 1 div div?
i don't have video js installed seems need re-initialize player itself.
reference: http://docs.videojs.com/docs/guides/setup.html
if web page or application loads video tag dynamically (ajax, appendchild, etc.), may not exist when page loads, you'll want manually set player instead of relying on data-setup attribute. this, first remove data-setup attribute tag there's no confusion around when player initialized. next, run following javascript time after video.js javascript library has loaded, , after video tag has been loaded dom.
videojs("example_video_1", {}, function(){ // player (this) initialized , ready. });
the first argument in videojs function id of video tag. replace own. second argument options object. allows set additional options can data-setup attribute. third argument 'ready' callback. once video.js has initialized call function. instead of using element id, can pass reference element itself.
videojs(document.getelementbyid('example_video_1'), {}, function() { // functionally same previous example. });
videojs(document.getelementsbyclassname('awesome_video_class')[0], {}, function() { // can grab element class if you'd like, make sure // if it's array pick 1 (here chose first). });
i hope you're looking for.
Comments
Post a Comment