javascript - 如何使用 javascript jquery 将具有多个 id 的数组制作为视频标签

标签 javascript jquery arrays

我正在使用自定义构建的 html5 视频。视频标签有一个唯一的ID。现在我想创建几个视频标签。

这就是仅 1 个视频的工作原理:

<video id="myVideo1" controls preload="auto" width="600" height="350" >
<source src="test.mp4" type="video/mp4" />
</video>

js:

$(document).ready(function(){
   var video = $('#myVideo1);
   // stuff goes her...

那么:我如何制作多个视频标签,每个标签都有自己的 id,并在这些 id 上使用 javascript 触发?

如何处理多个彼此独立的视频,如下所示?

 <video id="myVideo1" controls preload="auto" width="600" height="350" >
    <source src="test1.mp4" type="video/mp4" />
 </video>

 <video id="myVideo2" controls preload="auto" width="600" height="350" >
    <source src="test2.mp4" type="video/mp4" />
 </video>

 <video id="myVideo3" controls preload="auto" width="600" height="350" >
    <source src="test3.mp4" type="video/mp4" />
 </video>

启动视频的代码:

//bind video events
    $('.videoContainer')
    .append('<div id="init"></div>')
    .hover(function() {
        $('.control').stop().animate({'bottom':0}, 500);
        $('.caption').stop().animate({'top':0}, 500);
    }, function() {
        if(!volumeDrag && !timeDrag){
            $('.control').stop().animate({'bottom':-45}, 500);
            $('.caption').stop().animate({'top':-45}, 500);
        }
    })
    .on('click', function() {
        $('#init').remove();
        $('.btnPlay').addClass('paused');
        $(this).unbind('click');
        video[0].play();
    });
    $('#init').fadeIn(200);
});

最佳答案

您始终可以选择实际元素,而不是依赖 id。

$(document).ready(function(){
   $('video').each(function(){
       var video = $(this);

       // Do the rest of the instructions.
   });
});

关于javascript - 如何使用 javascript jquery 将具有多个 id 的数组制作为视频标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48720279/

相关文章:

javascript - jquery 1.3 中的父 > 子表示法

python - 如何在不使用 append,Python 的情况下将元素插入数组?

javascript - 改变鼠标移动的方差

javascript - 是否在使用 API 组合参数时遇到困难?

javascript - Ruby on Rails 和 Javascript 确认 Safari 12 中的弹出窗口

jquery - 如何使用 jQuery 滑动 div 关闭/打开页面

javascript - 递归启用/禁用 div 中按钮的方法?

python - 从 3 维数组生成列表

java - Android XML dataHandler getResources() 未定义

javascript - 全屏不适用于 Iphone 6s 和 5s