我在一个页面上有两个视频,用VideoJS实现。我想让他们敏感,并找到关于此主题的以下文章:Making Video.js Fluid for RWDVideoJS敏感的两个视频
但不幸的是,我无法让它与两个视频一起工作,无论我尝试过它总是只与其中一个工作..你有任何想法,我必须改变JavaScript代码,使它与两个工作?我甚至试图做两个函数并重命名所有变量。
这里是我的示例HTML:
<div class="videoWrapper">
<video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" poster="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video1/spot_01_still.jpg" data-setup='{ "controls": true, "autoplay": false, "preload": "auto" }'>
<source src="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video1/spot_01.flv" type='video/flv'>
<source src="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video1/spot_01.mp4" type='video/mp4'>
</video>
<video id="my_video_2" class="video-js vjs-default-skin" controls preload="auto" poster="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video2/spot_02_still.jpg" data-setup='{ "controls": true, "autoplay": false, "preload": "auto" }'>
<source src="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video2/spot_02.flv" type='video/flv'>
<source src="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video2/spot_02.mp4" type='video/mp4'>
</video>
</div>
CSS:
.videoWrapper video {
max-width: 100% !important;
height: auto !important;
}
#my_video_1,
#my_video_2 {
width:100% ;
height:auto ;
}
和JS:
_V_("my_video_1").ready(function(){
var myPlayer = this; // Store the video object
var aspectRatio = 9/16; // Make up an aspect ratio
function resizeVideoJS(){
// Get the parent element's actual width
var width = document.getElementById(myPlayer.id).parentElement.offsetWidth;
// Set width to fill parent element, Set height
myPlayer.width(width).height(width * aspectRatio);
}
resizeVideoJS(); // Initialize the function
window.onresize = resizeVideoJS; // Call the function on resize
});
为简洁起见,您可能会忽略它,但您是否在my_video_1和my_video_2上调用了'.ready'?如果没有,那么我会猜测那是你的问题。 – bmceldowney 2013-05-10 22:57:21
是的,我确实在两者上都调用了它。 – Sebsemillia 2013-05-14 21:07:21