简体   繁体   English

如何将videojs从一个div复制到另一个div?

[英]How to copy videojs from one div into another div?

I have a div with videojs in it 我有一个带有videojs的div

<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 to copy this video into another div 现在我正在尝试将此视频复制到另一个div中

jQuery(document).ready(function(){
    var video = jQuery('#video').clone(true, true);
    jQuery('#block').append( video );
});

It copies that video player, but it doesn't work (can't play the video). 它复制该视频播放器,但它不起作用(无法播放视频)。 What is the right way to copy videojs from one div into another div? 将videojs从一个div复制到另一个div的正确方法是什么?

I don't have Video JS installed but it seems like all you need to do is re-initialize the player itself. 我没有安装Video JS,但似乎你需要做的就是重新初始化播放器本身。

Reference: http://docs.videojs.com/docs/guides/setup.html 参考: http//docs.videojs.com/docs/guides/setup.html

If your web page or application loads the video tag dynamically (ajax, appendChild , etc.), so that it may not exist when the page loads, you'll want to manually set up the player instead of relying on the data-setup attribute. 如果您的网页或应用程序动态加载视频标签(ajax, appendChild等),以便在页面加载时可能不存在,您需要手动设置播放器而不是依赖数据设置属性。 To do this, first remove the data-setup attribute from the tag so there's no confusion around when the player is initialized. 为此,首先从标记中删除data-setup属性,以便在初始化播放器时不会产生混淆。 Next, run the following javascript some time after the Video.js javascript library has loaded, and after the video tag has been loaded into the DOM. 接下来,在加载Video.js javascript库之后,以及在将视频标记加载到DOM之后,运行以下javascript。

 videojs("example_video_1", {}, function(){ // Player (this) is initialized and ready. }); 

The first argument in the videojs function is the ID of your video tag. videojs函数中的第一个参数是视频标记的ID。 Replace it with your own. 用你自己的替换它。 The second argument is an options object. 第二个参数是选项对象。 It allows you to set additional options like you can with the data-setup attribute. 它允许您使用data-setup属性设置其他选项。 The third argument is a 'ready' callback. 第三个参数是'ready'回调。 Once Video.js has initialized it will call this function. 一旦Video.js初始化,它将调用此函数。 Instead of using an element ID, you can also pass a reference to the element itself. 您也可以传递对元素本身的引用,而不是使用元素ID。

 videojs(document.getElementById('example_video_1'), {}, function() { // This is functionally the same as the previous example. }); 

 videojs(document.getElementsByClassName('awesome_video_class')[0], {}, function() { // You can grab an element by class if you'd like, just make sure // if it's an array that you pick one (here we chose the first). }); 

I hope this is what you're looking for. 我希望这就是你要找的东西。

Copy the whole HTML from id#video into id#block like this: 将整个HTML从id#video复制到id#block,如下所示:

Example: http://codesheet.org/codesheet/T4qjlenn 示例: http//codesheet.org/codesheet/T4qjlenn

 $( "#copy" ).click(function() {
  var htmlString = $( "#video" ).html();
  $( "#block" ).html( htmlString );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM